From 35764b53dce7a2ab389479b5edca23cc7dac96ec Mon Sep 17 00:00:00 2001 From: xinghejd <31512683+xinghejd@users.noreply.github.com> Date: Wed, 27 Nov 2024 18:04:30 +0800 Subject: [PATCH] [PM-13923] [CLI] fix: resolve CLI file upload issue in Node.js 18+ (#11652) * fix: resolve CLI file upload issue in Node.js 18+ * remove useless try catch Signed-off-by: xinghejd <31512683+xinghejd@users.noreply.github.com> --------- Signed-off-by: xinghejd <31512683+xinghejd@users.noreply.github.com> Co-authored-by: Andreas Coroiu --- .../file-upload/bitwarden-file-upload.service.ts | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libs/common/src/platform/services/file-upload/bitwarden-file-upload.service.ts b/libs/common/src/platform/services/file-upload/bitwarden-file-upload.service.ts index 3d0c31ef3e..9a7b9a8982 100644 --- a/libs/common/src/platform/services/file-upload/bitwarden-file-upload.service.ts +++ b/libs/common/src/platform/services/file-upload/bitwarden-file-upload.service.ts @@ -8,23 +8,22 @@ export class BitwardenFileUploadService { apiCall: (fd: FormData) => Promise, ) { const fd = new FormData(); - try { - const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" }); - fd.append("data", blob, encryptedFileName); - } catch (e) { - if (Utils.isNode && !Utils.isBrowser) { + + if (Utils.isBrowser) { + const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" }); + fd.append("data", blob, encryptedFileName); + } else if (Utils.isNode) { fd.append( "data", Buffer.from(encryptedFileData.buffer) as any, { - filepath: encryptedFileName, + filename: encryptedFileName, contentType: "application/octet-stream", } as any, ); } else { - throw e; + throw new Error("Unsupported environment"); } - } await apiCall(fd); }