Example #1
0
        public JsonResult Upload(IFormFile formFile)
        {
            Console.WriteLine("开始上传");
            var filePath = Directory.GetCurrentDirectory() +
                           "/wwwroot/userfile/" +
                           formFile.FileName.Substring(formFile.FileName.LastIndexOf("\\") + 1);
            var str = "";
            var s   = "";

            //UploadQiNiuResult result = new UploadQiNiuResult();
            if (formFile.Length > 0)
            {
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    formFile.CopyTo(stream);
                }
                //var stream = formFile.OpenReadStream();
                //var bytes = new byte[stream.Length];
                //stream.Read(bytes, 0, bytes.Length);
                //stream.Seek(0, SeekOrigin.Begin);
                //result = UploadImgToQiNiu(bytes, Guid.NewGuid().ToString("N"));
                var accessKeyId     = "LTAI4FfhUHPcQ1VHcKN5wEHc";
                var accessKeySecret = "F2zwYrZ4xKUwayfhXWXmthzLKiMXnp ";
                var endpoint        = @"oss-cn-zhangjiakou.aliyuncs.com";
                var bucketName      = "chakk";

                // 上传文件
                s = Guid.NewGuid().ToString("N");
                AliOssHelper.PutObject(accessKeyId, accessKeySecret, endpoint, bucketName, s, filePath);
                str = AliOssHelper.GetIamgeUri(accessKeyId, accessKeySecret, endpoint, bucketName, s);
            }

            return(Success(new { file = str, lowFile = s }));
        }
Example #2
0
        /// <summary>
        ///  获取上传参数信息
        /// </summary>
        /// <returns></returns>
        public async Task <Resp <BucketUploadPara> > GetUploadPara(string category)
        {
            var checkRes = await CheckStorageAccount();

            return(checkRes.IsSuccess()
                ? AliOssHelper.GetUploadPara(UserContext.Identity.id, category)
                : new Resp <BucketUploadPara>().WithResp(checkRes));
        }
Example #3
0
        public async Task <Resp> UploadNotify(UploadFileMo mo, string token, string key)
        {
            mo.InitialBaseFromContext();//不要放在下边,下边会给用户Id,和租户Id 根据实际信息赋值

            var res = AliOssHelper.FormatUploadMo(mo, token, key);

            if (!res)
            {
                return(new Resp(RespTypes.ParaError, "不正确的参数信息"));
            }

            // 1.  更新租户存储统计信息
            var storageUpdateRes = await FileStorageRep.Instance.UpdateUseSize(mo.owner_tid, mo.size);

            if (storageUpdateRes.IsSuccess())
            {
                // 2.  添加条目信息
                return(await UploadFileRep.Instance.Add(mo));
            }
            return(storageUpdateRes);
        }