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:
29
src/services/bitwardenFileUpload.service.ts
Normal file
29
src/services/bitwardenFileUpload.service.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user