public async Task <IActionResult> CreateDirectUploadUrl([FromBody] CreateDirectUploadUrlRequest request, [FromQuery(Name = "expiresInSeconds")] int?expiresInSeconds) { try { var expiresIn = expiresInSeconds ?? IStorageService.DEFAULT_EXPIRES_IN_SECONDS; var storageService = _storageServiceProvider.Service(request.StorageService); if (storageService.SupportsDirectUpload && storageService.AllowDirectUpload) { var storageId = Guid.NewGuid().ToString(); var directUploadUrl = await _storageServiceProvider.Service(request.StorageService).GetDirectUploadUrl(storageId, expiresIn); var expiresAt = DateTime.UtcNow.AddSeconds(expiresIn); var response = new FileDirectUpload { DirectUploadUrl = directUploadUrl, ExpiresAt = expiresAt, StorageId = storageId, StorageService = _storageServiceProvider.Service(request.StorageService).Name }; return(Ok(response)); } else { return(StatusCode(StatusCodes.Status405MethodNotAllowed)); } } catch (Exception ex) { return(BuildErrorResponse(ex, _logger)); } }
public async Task <FileDirectUpload> CreateFileDirectUpload(string storageService = null, int?expiresInSeconds = null, string asUserKey = null, string bearerToken = null, bool logToConsole = true) { var url = expiresInSeconds == null ? $"files/directuploadurl" : $"files/directuploadurl?expiresInSeconds={expiresInSeconds.Value}"; var request = new CreateDirectUploadUrlRequest { StorageService = storageService }; var directUploadInfo = await Post <CreateDirectUploadUrlRequest, FileDirectUpload>(request, url, asUserKey, bearerToken); if (logToConsole) { Console.WriteLine($"Retrieved DirectUploadInfo: {ToJson(directUploadInfo)}"); } ; return(directUploadInfo); }