예제 #1
0
        public async Task <IActionResult> Upload(IFormFile file)
        {
            var putPolicy = new PutPolicy
            {
                Scope           = $"goldhouse",
                DeleteAfterDays = 1
            };

            var result = await _qiniu.UploadStream(file.OpenReadStream(), putPolicy, "Test.txt", null);

            return(Ok(result));
        }
예제 #2
0
 public void FileUpload()
 {
     try
     {
         int fileid = 0;
         var files  = Request.Form.Files;
         if (files.Count > 0)
         {
             var file = files.First();
             if (file.Length > (200 * 1024 * 1024))
             {
                 //return Json("文件过大,不能大于200M");
             }
             PutExtra putExtra = new PutExtra();// { ProgressHandler = UploadProgressHandler,  ResumeRecordFile  };
             putExtra.ProgressHandler  = UploadProgressHandler;
             putExtra.UploadController = DefaultUploadController;
             putExtra.ResumeRecordFile = ResumeHelper.GetDefaultRecordKey($"{Environment.CurrentDirectory}\\{file.FileName}", file.FileName);
             var aa = putExtra.ResumeRecordFile;
             putExtra.ResumeRecordFile = file.FileName + ".progress";
             HttpResult result = new HttpResult();
             Stream     stream = file.OpenReadStream();
             result = qiniu.UploadStream(file.FileName, stream, putExtra);
             if (result.Code == (int)HttpCode.OK)
             {
                 //todo 入库文件信息
                 var     rj            = JObject.Parse(result.Text);
                 string  hash          = rj["hash"].ToString();
                 string  key           = rj["key"].ToString();
                 var     hashentity    = ossfile.GetList(t => t.FileHash == hash);
                 OssFile ossFileEntity = new OssFile
                 {
                     FileKey    = key,
                     FileHash   = hash,
                     FileDomain = ""
                 };
                 ossfile.Insert_Return_Id(ossFileEntity, out fileid);
             }
             //检查删除文件
             if (System.IO.File.Exists($"{Environment.CurrentDirectory}\\{file.FileName}"))
             {
                 System.IO.File.Delete($"{Environment.CurrentDirectory}\\{file.FileName}");
             }
         }
     }
     catch (Exception ex)
     {
         // return Json(ex.Message);
     }
 }