mirror of
https://github.com/System-End/cdn.git
synced 2026-04-19 16:18:17 +00:00
Migrated fully to S3 API
This commit is contained in:
parent
779fe5a9ea
commit
495d1410a9
1 changed files with 0 additions and 32 deletions
|
|
@ -1,32 +0,0 @@
|
|||
const B2 = require('backblaze-b2');
|
||||
const logger = require('./config/logger');
|
||||
|
||||
const b2 = new B2({
|
||||
applicationKeyId: process.env.B2_APP_KEY_ID,
|
||||
applicationKey: process.env.B2_APP_KEY
|
||||
});
|
||||
|
||||
async function uploadToBackblaze(userDir, uniqueFileName, buffer) {
|
||||
try {
|
||||
await b2.authorize();
|
||||
const {data} = await b2.getUploadUrl({
|
||||
bucketId: process.env.B2_BUCKET_ID
|
||||
});
|
||||
|
||||
await b2.uploadFile({
|
||||
uploadUrl: data.uploadUrl,
|
||||
uploadAuthToken: data.authorizationToken,
|
||||
fileName: `${userDir}/${uniqueFileName}`,
|
||||
data: buffer
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
logger.error('B2 upload failed:', error.message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {uploadToBackblaze};
|
||||
|
||||
// So easy i love it!
|
||||
Loading…
Add table
Reference in a new issue