Last active
April 29, 2024 02:05
-
-
Save SazumiVicky/923e54dc9c192a71f0879972dae54650 to your computer and use it in GitHub Desktop.
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
/* | |
* 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