1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 18:23:31 +00:00

Upload to Azure strorage blobs (#296)

* Implemen AzureStorageService

handes uploading files to azure blob

* Correct one-shot size

* Add azureStorage.service abstraction

* Rename azure upload method

* Prefer abstractions in DI

* Abstract file upload to a single service handling uploads

* Fallback to legacy upload method

* Linter fix

* Limit legacy upload to 404 error
This commit is contained in:
Matt Gibson
2021-03-25 10:20:38 -05:00
committed by GitHub
parent 7f3bbd6e51
commit cfc7687815
11 changed files with 388 additions and 40 deletions

View File

@@ -0,0 +1,29 @@
import { ApiService } from '../abstractions/api.service';
import { Utils } from '../misc/utils';
import { CipherString } from '../models/domain';
import { SendResponse } from '../models/response/sendResponse';
export class BitwardenFileUploadService
{
constructor(private apiService: ApiService) { }
async upload(sendResponse: SendResponse, fileName: CipherString, data: ArrayBuffer) {
const fd = new FormData();
try {
const blob = new Blob([data], { type: 'application/octet-stream' });
fd.append('data', blob, fileName.encryptedString);
} catch (e) {
if (Utils.isNode && !Utils.isBrowser) {
fd.append('data', Buffer.from(data) as any, {
filepath: fileName.encryptedString,
contentType: 'application/octet-stream',
} as any);
} else {
throw e;
}
}
await this.apiService.postSendFile(sendResponse.id, sendResponse.file.id, fd);
}
}