You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB

2 years ago
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Volo.Abp.Application.Services;
  7. using System.IO;
  8. using Aliyun.OSS;
  9. using System.Security.AccessControl;
  10. namespace Shentun.Peis.Books
  11. {
  12. public static class QiNiuHelper
  13. {
  14. // 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM
  15. // 用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
  16. const string accessKeyId = "LTAI5tBNDdiV7JudVvaQhU1t";
  17. const string accessKeySecret = "sA6k0TbeX8w2cv7YhcTed7wyt0EBdN";
  18. // yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint
  19. // 填写为https://oss-cn-hangzhou.aliyuncs.com。
  20. const string endpoint = "https://oss-cn-beijing.aliyuncs.com";
  21. // 填写Bucket名称。
  22. const string bucketName = "whdshake";
  23. public static void Upload_QiNiu()
  24. {
  25. // 填写Object完整路径。Object完整路径中不能包含Bucket名称。
  26. // 即:objectName为文件上传到阿里云OSS上的文件夹路径
  27. var objectName = "imgae/222.png";
  28. // 填写本地文件的完整路径。如果未指定本地路径,
  29. // 则默认从示例程序所属项目对应本地路径中上传文件。
  30. var localFilename = @"D:\aaa.png";
  31. //System.Web.HttpContext.Current.Server.MapPath("imgae.png");
  32. // 创建OssClient实例。
  33. var client = new Aliyun.OSS.OssClient(endpoint, accessKeyId, accessKeySecret);
  34. try
  35. {
  36. // 上传文件。
  37. client.PutObject(bucketName, objectName, localFilename);
  38. Console.WriteLine("1");
  39. }
  40. catch (Exception ex)
  41. {
  42. Console.WriteLine(ex.Message);
  43. }
  44. }
  45. }
  46. }