[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 <acoroiu@bitwarden.com>
This commit is contained in:
parent
4c43c72dca
commit
35764b53dc
|
@ -8,22 +8,21 @@ export class BitwardenFileUploadService {
|
||||||
apiCall: (fd: FormData) => Promise<any>,
|
apiCall: (fd: FormData) => Promise<any>,
|
||||||
) {
|
) {
|
||||||
const fd = new FormData();
|
const fd = new FormData();
|
||||||
try {
|
|
||||||
|
if (Utils.isBrowser) {
|
||||||
const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" });
|
const blob = new Blob([encryptedFileData.buffer], { type: "application/octet-stream" });
|
||||||
fd.append("data", blob, encryptedFileName);
|
fd.append("data", blob, encryptedFileName);
|
||||||
} catch (e) {
|
} else if (Utils.isNode) {
|
||||||
if (Utils.isNode && !Utils.isBrowser) {
|
|
||||||
fd.append(
|
fd.append(
|
||||||
"data",
|
"data",
|
||||||
Buffer.from(encryptedFileData.buffer) as any,
|
Buffer.from(encryptedFileData.buffer) as any,
|
||||||
{
|
{
|
||||||
filepath: encryptedFileName,
|
filename: encryptedFileName,
|
||||||
contentType: "application/octet-stream",
|
contentType: "application/octet-stream",
|
||||||
} as any,
|
} as any,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw new Error("Unsupported environment");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await apiCall(fd);
|
await apiCall(fd);
|
||||||
|
|
Loading…
Reference in New Issue