• aws s3 文件上传


     public class AwsS3Helper
        {
            // 请求S3的凭据
            AWSCredentials awsCredentials = new BasicAWSCredentials(ConfigurationManager.AppSettings["accessKey"]
                , ConfigurationManager.AppSettings["secretKey"]);
            //  获取桶的名称
            private string bucketName = ConfigurationManager.AppSettings["bucketName"].ToString();
            //  获取桶下文件夹名称
            private string bucketFileName = ConfigurationManager.AppSettings["bucketFileName"].ToString();
    
            private AmazonS3Client client
            {
                get
                {
                    return new AmazonS3Client(awsCredentials, RegionEndpoint.APNortheast1);
                }
            }
    
            /// <summary>
            /// 上传文件
            /// </summary>
            /// <param name="filePath">文件所在地址</param>
            /// <returns></returns>
            public string UploadFile(string filePath,string fileName)
            {
                try
                {
                    string bucketPath = GetFilePath();
                    PutObjectRequest request = new PutObjectRequest
                    {
                        BucketName = bucketPath,
                        Key = fileName,
                        FilePath = filePath
                    };
                    PutObjectResponse response = client.PutObject(request);
                    return response.HttpStatusCode.ToString(); ;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
    
            /// <summary>
            /// 路径处理
            /// </summary>
            /// <param name="folderName"></param>
            /// <returns></returns>
            public string GetFilePath()
            {
                //// 正式
                string filePath = bucketName + "/"+ bucketFileName;
                return filePath;
            }
    
        }
      string FileName = "abc" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt";
      string InterfaceFilePath = FilePath.Trim('/') +"/"+ FileName;
    
      S3.UploadFile(InterfaceFilePath, FileName);
    萌橙 你瞅啥?
  • 相关阅读:
    Tjoi 2017 异或和
    Noi 十连测 建造记者站
    Noi 十连测 基因改造计划
    Noi 十连测 人生的经验
    NOI 十连测 Round 5 T2 运河计划
    NOI 十连测 Round 5 T1
    【ZJOI2018】迷宫
    BZOJ 十连测 day5 T3
    BZOJ 十连测 可持久化字符串
    BZOJ 十连测 二进制的世界
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/15192394.html
Copyright © 2020-2023  润新知