Last active
March 28, 2024 16:44
-
-
Save erfg12/c742fc99b278cff4ce4fd7f5f76388e5 to your computer and use it in GitHub Desktop.
BunnyCDN API PUT for NodeJS. Use startUploading function to start the uploading process of all files in a directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
var fs = require('fs'); | |
function uploadItem(item) { | |
console.log('uploading ' + item); | |
request({ | |
method: 'PUT', | |
preambleCRLF: true, | |
postambleCRLF: true, | |
uri: 'https://storage.bunnycdn.com/newagetest//path/filename', | |
headers: { | |
'AccessKey': 'API_KEY_HERE' | |
}, | |
multipart: [ | |
{ body: fs.createReadStream('FILE_NAME_HERE') } | |
] | |
}, | |
function (error, response, body) { | |
if (error) { | |
return console.error('upload failed:', error); | |
} | |
}); | |
} | |
function startUploading() { | |
fs.readdir(process.argv[2], (err, files) => { | |
(async () => { | |
files.forEach(file => { | |
setTimeout(function intervalFunc() { uploadItem(process.argv[2] + '/' + file) }, slowdown); | |
slowdown = slowdown + 300; | |
}); | |
})(); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey ! Can you help mw with how to upload video from NodeJS server to bunny.net and then access them.