private object FireRecordToObject(FireRecord newFire,string bucket)
 {
     var fireObj = new
     {
         fileId = newFire.Id.ToString(),
         server = newFire.UploadServerUrl,
         accessKey = newFire.Id.ToString(),
         bucket = bucket,
         serverType = AliOSSFileInfo.AliOssServerType,
         expireAt = DateTimeUtil.ToString(DateTime.UtcNow.AddDays(7))
     };
     return fireObj;
 }
 private FireRecord GenerateNewFireRecord(string fileType,int fileSize,string accountId,string uploadUrl,string bucket)
 {
     var aliOssInfo = new AliOSSFileInfo()
     {
         Bucket = bucket
     };
     var newFire = new FireRecord()
     {
         CreateTime = DateTime.UtcNow,
         FileSize = fileSize,
         FileType = fileType,
         IsSmallFile = fileSize < 1024 * 256,
         State = (int)FireRecordState.Create,
         AccountId = accountId,
         AccessKeyConverter = "",
         UploadServerUrl = uploadUrl,
         ServerType = AliOSSFileInfo.AliOssServerType,
         Extra = Newtonsoft.Json.JsonConvert.SerializeObject(aliOssInfo)
     };
     return newFire;
 }
Пример #3
0
        public async Task<object> PostOne(string fileType, int fileSize)
        {
            NLog.LogManager.GetCurrentClassLogger().Info("File Post");
            try
            {
                var fService = Startup.AppServiceProvider.GetFireService();
                var accountId = Request.Headers["accountId"];
                var newFire = new FireRecord
                {
                    CreateTime = DateTime.UtcNow,
                    FileSize = fileSize,
                    FileType = fileType,
                    IsSmallFile = fileSize < 1024 * 256,
                    State = (int)FireRecordState.Create,
                    AccountId = accountId,

                    UploadServerUrl = Startup.AppUrl + "/UploadFile",
                    AccessKeyConverter = ""
                };
                var r = await fService.CreateFireRecord(newFire);
                var fileId = r.Id.ToString();
                var accessKey = fileId;
                return new
                {
                    server = newFire.UploadServerUrl,
                    accessKey = accessKey,
                    fileId = fileId
                };
            }
            catch (Exception ex)
            {
                NLog.LogManager.GetLogger("Warning").Warn(ex.Message);
                throw;
            }
        }
Пример #4
0
 public async Task<FireRecord> CreateFireRecord(FireRecord newFireRecord)
 {
     await Client.GetDatabase(FireDBName).GetCollection<FireRecord>("FireRecord").InsertOneAsync(newFireRecord);
     return newFireRecord;
 }