upload-imgbb
v1.4.0
Published
Uploads Media to imgbb (links or stream) and returns uploaded link
Downloads
12
Readme
const { uploadLink } = require('upload-imgbb');
async function uploadImage(link) {
try {
const uploadedLink = await uploadLink(link);
console.log('Uploaded image link:', uploadedLink);
} catch (error) {
console.error('Error uploading image:', error.message);
}
}
uploadImage('https://example.com/image.jpg');
Note: Replace 'https://example.com/image.jpg'
with the actual URL of the image you want to upload.
const { upload } = require('upload-imgbb'); // Updated import for new function
// Example usage of the updated upload function
async function uploadImage(imageStreamOrLink) {
try {
const uploadedData = await upload(imageStreamOrLink);
console.log('Uploaded image data:', uploadedData);
} catch (error) {
console.error('Error uploading image:', error.message);
}
}
// Call the function with either the image stream or the image link
uploadImage('https://example.com/image.jpg'); // Image link example
// or
// uploadImage(imageReadStream); // Image stream example
Parameters
imageStreamOrLink
(string or stream): Either the URL of the image you want to upload or a readable stream of the image file.json
(optional, boolean): Set this parameter totrue
if you want to receive the response data as a JSON object. By default, it returns the uploaded image URL.
Return Value
The function returns the uploaded image URL by default or the entire response data as a JSON object if the json
parameter is set to true
.
Important: This updated upload
function supports both image streams and image links, providing more flexibility for uploading media files.# upload-imgbb