public async Task <IActionResult> UploadBioVideoAsync([FromForm] UploadBioVideoView viewModel) { var domainUrl = (HttpContext.Request.IsHttps ? "https://" : "http://") + HttpContext.Request.Host.Value; var model = await _fileService.UploadBioVideoAsync(viewModel).ConfigureAwait(false); model.UploadedFileUrl = domainUrl + $"/api/File/get-download-video/{viewModel?.UserId}"; return(Ok(model)); }
public async Task <IFileResponse> UploadBioVideoAsync(UploadBioVideoView model) { try { var userInfo = await _appDbContext.UserInfos.Include(k => k.User).FirstOrDefaultAsync(k => k.Id == model.UserId); var data = new File() { IdGuid = Guid.NewGuid(), SizeMb = GetFileSize(model.File.Length), Name = model.File.FileName, ProviderName = "SqlProvider", ExtraParams = model.ExtraParams, Created = DateTime.UtcNow, MimeType = model.File.ContentType, Modified = DateTime.UtcNow, CreatedBy = userInfo.Email, ModifiedBy = userInfo.Email }; var savedEntity = (await _appDbContext.Files.AddAsync(data)).Entity; await _appDbContext.SaveChangesAsync(); var profile = await _appDbContext.Profiles.FirstOrDefaultAsync(k => k.Id == model.UserId); profile.ExpressYourselfUrl = _encryption.Encrypt(savedEntity.Id.ToString()); await _appDbContext.SaveChangesAsync(); var fileDb = new FileDB() { Id = savedEntity.IdGuid, Bytes = StreamToBytes(model.File.OpenReadStream()) }; await _fileDbContext.FileDB.AddAsync(fileDb); await _fileDbContext.SaveChangesAsync(); return(new FileResponse(true, "Success", HttpStatusCode.Accepted)); } catch (Exception e) { return(new FileResponse(e)); } }