Ejemplo n.º 1
0
        /// <summary>
        /// 批量上传文件,非断点上传
        /// </summary>
        /// <param name="files">上传文件对象集合</param>
        /// <param name="bucketName">aliyunoss创建的bucketName,一个项目一个bucket,如果不传值会上传到默认的bucket下</param>
        /// <returns></returns>
        public static ServerResponse <List <FileData> > UpLoadMultipleFile(IFormFileCollection files, string bucketName, string uploadUserId = "")
        {
            try
            {
                List <FileData> list = new List <FileData>();
                foreach (var file in files)
                {
                    FileData fileData = UploadFileToOSS(file, bucketName, uploadUserId);
                    if (fileData != null)
                    {
                        list.Add(fileData);
                    }
                    else
                    {
                        return(ResponseProvider.Error <List <FileData> >("未找到文件!"));
                    }
                }

                return(ResponseProvider.Success(list, "成功"));
            }
            catch (Exception ex)
            {
                return(ResponseProvider.Error <List <FileData> >(ex.Message));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 删除系统对应的bucketName所对应的OSS文件
 /// </summary>
 /// <param name="ossPath">存储到oss的文件地址,如: 20181229/20181229155625123.png</param>
 /// <param name="bucketName">系统所对应的bucketName,如果不传值会上传到默认的bucket下</param>
 /// <returns></returns>
 public static ServerResponse DeleteAlyunOSSFile(string ossPath, string bucketName = "")
 {
     try
     {
         OssClient client = new OssClient(AppConfig.GetSection("AliyunOSS:Endpoint"), AppConfig.GetSection("AliyunOSS:AccessKeyId"), AppConfig.GetSection("AliyunOSS:AccessKeySecret"));
         client.DeleteObject(bucketName, ossPath);
         return(ResponseProvider.Success("删除成功"));
     }
     catch (OssException ex)
     {
         return(ResponseProvider.Error("OssException异常:" + ex.Message));
     }
     catch (Exception ex)
     {
         return(ResponseProvider.Error("系统异常失败" + ex.Message));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 单个文件断点续传,上传到aliyun Oss
 /// </summary>
 /// <param name="file"></param>
 /// <param name="bucketName">所对应系统的bucketName</param>
 /// <returns></returns>
 public static ServerResponse <FileData> UploadFilePonit(IFormFile file, string bucketName, string uploadUserId = "")
 {
     try
     {
         string   objectName = string.Empty;
         FileData fileData   = null;
         if (file != null && !string.IsNullOrEmpty(file.FileName))
         {
             fileData = UploadFilePonitToOSS(file, bucketName, uploadUserId);
             return(ResponseProvider.Success(fileData, "成功"));
         }
         else
         {
             return(ResponseProvider.Error <FileData>("未找到文件!"));
         }
     }
     catch (Exception ex)
     {
         return(ResponseProvider.Error <FileData>(ex.Message));
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 单文件上传,非断点上传
        /// </summary>
        /// <param name="file">上传文件对象</param>
        /// <param name="bucketName">aliyunoss创建的bucketName,一个项目一个bucket</param>
        /// <returns></returns>
        public static ServerResponse <FileData> UpLoadSingleFile(IFormFile file, string bucketName, string uploadUserId = "")
        {
            string objectName = string.Empty;

            try
            {
                FileData fileData = UploadFileToOSS(file, bucketName, uploadUserId);
                if (fileData != null)
                {
                    return(ResponseProvider.Success(fileData, "成功"));
                }
                else
                {
                    return(ResponseProvider.Error <FileData>("未找到文件!"));
                }
            }
            catch (Exception ex)
            {
                //记录日志
                return(ResponseProvider.Error <FileData>(ex.Message));
            }
        }