mirror of
https://github.com/bitwarden/browser
synced 2025-12-20 18:23:31 +00:00
* 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
28 lines
904 B
TypeScript
28 lines
904 B
TypeScript
import { ApiService } from '../abstractions/api.service';
|
|
|
|
import { Utils } from '../misc/utils';
|
|
|
|
export class BitwardenFileUploadService
|
|
{
|
|
constructor(private apiService: ApiService) { }
|
|
|
|
async upload(encryptedFileName: string, encryptedFileData: ArrayBuffer, apiCall: (fd: FormData) => Promise<any>) {
|
|
const fd = new FormData();
|
|
try {
|
|
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(encryptedFileData) as any, {
|
|
filepath: encryptedFileName,
|
|
contentType: 'application/octet-stream',
|
|
} as any);
|
|
} else {
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
await apiCall(fd);
|
|
}
|
|
}
|