Skip to content

Instantly share code, notes, and snippets.

@SazumiVicky
Last active April 29, 2024 02:05
Show Gist options
  • Save SazumiVicky/923e54dc9c192a71f0879972dae54650 to your computer and use it in GitHub Desktop.
Save SazumiVicky/923e54dc9c192a71f0879972dae54650 to your computer and use it in GitHub Desktop.
/*
* dev: Sazumi Viki
* ig: @moe.sazumiviki
* gh: github.com/sazumivicky
* site: sazumi.moe
*/
const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs');
async function sazumiCdn(filePath) {
const formData = new FormData();
formData.append('fileInput', fs.createReadStream(filePath));
try {
const response = await fetch('https://cdn.sazumi.moe/upload', {
method: 'POST',
body: formData
});
if (response.ok) {
const fileUrl = await response.json(); // Change from response.text() to response.json()
console.log('Succesfully:', fileUrl);
} else {
const errorResponse = await response.json(); // Change from response.statusText to response.json()
console.error('oops something went wrong:', errorResponse);
}
} catch (error) {
console.error('oops something went wrong:', error.message);
}
}
// Example usage:
sazumiCdn('/path/to/your/file.jpg');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment