1
0
mirror of https://github.com/bitwarden/mobile synced 2025-12-11 05:43:30 +00:00

Attachment azure upload blobs (#1345)

* Update Size limits

* Add new Api paths for direct upload of Cipher Attachments

* Add Attachment upload to fileUploadService

* Save with direct upload and fallback to legacy uplaod

CipherID is required for direct upload to request an upload URL

* Inform on when to remove legacy code

* Test Attachment upload
This commit is contained in:
Matt Gibson
2021-03-30 18:42:43 -05:00
committed by GitHub
parent 04aeddc5de
commit ce0b8bc62d
15 changed files with 292 additions and 25 deletions

View File

@@ -19,6 +19,35 @@ namespace Bit.Core.Services {
private readonly AzureFileUploadService _azureFileUploadService;
private readonly ApiService _apiService;
public async Task UploadCipherAttachmentFileAsync(AttachmentUploadDataResponse uploadData,
string encryptedFileName, byte[] encryptedFileData)
{
try
{
switch (uploadData.FileUploadType)
{
case FileUploadType.Direct:
await _bitwardenFileUploadService.Upload(encryptedFileName, encryptedFileData,
fd => _apiService.PostAttachmentFileAsync(uploadData.CipherResponse.Id, uploadData.AttachmentId, fd));
break;
case FileUploadType.Azure:
Func<Task<string>> renewalCallback = async () =>
{
var response = await _apiService.RenewAttachmentUploadUrlAsync(uploadData.CipherResponse.Id, uploadData.AttachmentId);
return response.Url;
};
await _azureFileUploadService.Upload(uploadData.Url, encryptedFileData, renewalCallback);
break;
default:
throw new Exception($"Unkown file upload type: {uploadData.FileUploadType}");
}
} catch
{
await _apiService.DeleteCipherAttachmentAsync(uploadData.CipherResponse.Id, uploadData.AttachmentId);
throw;
}
}
public async Task UploadSendFileAsync(SendFileUploadDataResponse uploadData, CipherString fileName, byte[] encryptedFileData)
{
try
@@ -41,10 +70,10 @@ namespace Bit.Core.Services {
throw new Exception("Unknown file upload type");
}
}
catch (Exception e)
catch (Exception)
{
await _apiService.DeleteSendAsync(uploadData.SendResponse.Id);
throw e;
throw;
}
}
}