Skip to content

Commit

Permalink
Merge pull request #392 from TwoAbove/develop
Browse files Browse the repository at this point in the history
Updated b2 uploader
  • Loading branch information
TwoAbove authored Sep 10, 2024
2 parents bb1bb63 + 9f53d3b commit bda0dce
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions server/server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit bda0dce

Please sign in to comment.