Skip to content

Instantly share code, notes, and snippets.

@erfg12
Last active March 28, 2024 16:44
Show Gist options
  • Save erfg12/c742fc99b278cff4ce4fd7f5f76388e5 to your computer and use it in GitHub Desktop.
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.
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;
});
})();
})
}
@Nainik2509
Copy link

Hey ! Can you help mw with how to upload video from NodeJS server to bunny.net and then access them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment