From 9f53d3b30421afe5caa54f118a02fca7f0a233ac Mon Sep 17 00:00:00 2001 From: Seva Maltsev Date: Mon, 9 Sep 2024 20:16:35 -0400 Subject: [PATCH] Updated b2 uploader --- server/server.mjs | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/server/server.mjs b/server/server.mjs index aa741c3..39e3ca0 100644 --- a/server/server.mjs +++ b/server/server.mjs @@ -119,18 +119,23 @@ const uploadToB2 = async (data, bucketId, fileName) => { if (!hasB2) { return; } - const uploadUrl = await b2.getUploadUrl({ - bucketId, - }); - - const upload = await b2.uploadFile({ - uploadUrl, - uploadAuthToken: uploadUrl.data.authorizationToken, - fileName, - data, - }); - - return upload; + try { + const uploadUrlResponse = await b2.getUploadUrl({ + bucketId, + }); + + const upload = await b2.uploadFile({ + uploadUrl: uploadUrlResponse.data.uploadUrl, + uploadAuthToken: uploadUrlResponse.data.authorizationToken, + fileName, + data, + }); + + return upload; + } catch (error) { + console.error("Error in uploadToB2:", error); + throw error; + } }; const m = multer();