/// <summary> /// 通知实体转化为上传实体对象 /// </summary> /// <param name="req"></param> /// <returns></returns> public static UploadFileMo ConvertToMo(this UploadNotifyReq req) { var mo = new UploadFileMo(); mo.mime_type = req.mime_type; mo.size = req.size; mo.bucket = req.bucket; mo.add_time = DateTime.Now.ToUtcSeconds(); mo.from_app_id = AppReqContext.Identity.app_id; mo.status = CommonStatus.Original; mo.id = NumHelper.SnowNum().ToString(); return(mo); }
public async Task <Resp> ali([FromQuery] string t) { var token = t; var size = Request.Form["size"].FirstOrDefault(); var bucket = Request.Form["bucket"].FirstOrDefault(); var key = Request.Form["object"].FirstOrDefault(); var mime_type = Request.Form["mimeType"].FirstOrDefault(); var mo = new UploadFileMo { mime_type = mime_type, size = size.ToInt32(), bucket = bucket, status = CommonStatus.Original }; return(await _service.UploadNotify(mo, token, key)); }
/// <summary> /// 格式化 上传文件实体 /// </summary> /// <param name="mo"></param> /// <param name="token"></param> /// <param name="key"></param> /// <returns></returns> public static bool FormatUploadMo(UploadFileMo mo, string token, string key) { if (string.IsNullOrEmpty(token)) { return(false); } var encryptKey = HMACSHA.EncryptBase64(key, OssTokenSecret); if (token != encryptKey) { return(false); } var splitKey = key.Split('/'); var length = splitKey.Length; if (length < 4) { return(false); } var splitUser = splitKey[length - 3].Split('-'); if (splitUser.Length < 2) { return(false); } mo.owner_tid = splitKey[length - 4]; //var appType = splitUser[0].ToInt32(); mo.owner_tid = mo.owner_tid; mo.owner_uid = splitUser[1]; mo.url = string.Concat(GetDomainByBucket(mo.bucket), "/", key); if (mo.mime_type.StartsWith("image")) { mo.type = UploadFileType.Image; } return(true); }
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); }