Uploads Media to imgbb (links or stream) and returns uploaded link
npm install upload-imgbb
Deprecated Upload Function (uploadLink)
``javascript
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');
`'https://example.com/image.jpg'
Note: Replace with the actual URL of the image you want to upload.
---
`javascript
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
`
- 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 to true if you want to receive the response data as a JSON object. By default, it returns the uploaded image URL.
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