mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
Attachment azure upload blobs (#312)
* Add direct attachment download and upload API endpoints * Use direct download method Enable download of emergency access attachments through EmergencyAccessId * Match new Server model items * New Server model for creating attachments. Provides a url to upload data to, the type of upload, and the Cipher Response expected by the previous call * Use direct upload url and scheme * Report Failed single shot azure uploads * Add cipher attachment upload to file upload service * Deprecate legacy api methods * Handle old servers missing new upload api methods * Improve Send error handling * Fallback attachment downloads on new endpoint not found Limit upload size to the new 500MB * Improve error handling * lint fixes
This commit is contained in:
@@ -2,28 +2,26 @@ 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) {
|
||||
async upload(encryptedFileName: string, encryptedFileData: ArrayBuffer, apiCall: (fd: FormData) => Promise<any>) {
|
||||
const fd = new FormData();
|
||||
try {
|
||||
const blob = new Blob([data], { type: 'application/octet-stream' });
|
||||
fd.append('data', blob, fileName.encryptedString);
|
||||
const blob = new Blob([encryptedFileData], { type: 'application/octet-stream' });
|
||||
fd.append('data', blob, encryptedFileName);
|
||||
} catch (e) {
|
||||
if (Utils.isNode && !Utils.isBrowser) {
|
||||
fd.append('data', Buffer.from(data) as any, {
|
||||
filepath: fileName.encryptedString,
|
||||
fd.append('data', Buffer.from(encryptedFileData) as any, {
|
||||
filepath: encryptedFileName,
|
||||
contentType: 'application/octet-stream',
|
||||
} as any);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
await this.apiService.postSendFile(sendResponse.id, sendResponse.file.id, fd);
|
||||
|
||||
await apiCall(fd);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user