Deleting images in Imgbb via API - javascript

i'm using the imgbb API since it is very straghtforward to use and quite cheap. The problem is that the documentation is very poor and it does not explain how to delete an image through the API. I want to be able to delete the photo from my server in the case something happens (ex. if I delete a user).
My server is written in node.js.
pd. Also the response object I get after uploading an image is this one:
{
data: {
id: 'c3VRs4x',
title: 'client1-Bali',
url_viewer: 'https://ibb.co/c3VRs4x',
url: 'https://i.ibb.co/Pj0JVqt/client1-Bali.jpg',
display_url: 'https://i.ibb.co/1QjB4Fb/client1-Bali.jpg',
size: 60385,
time: '1594835546',
expiration: '0',
image: {
filename: 'client1-Bali.jpg',
name: 'client1-Bali',
mime: 'image/jpeg',
extension: 'jpg',
url: 'https://i.ibb.co/Pj0JVqt/client1-Bali.jpg'
},
thumb: {
filename: 'client1-Bali.jpg',
name: 'client1-Bali',
mime: 'image/jpeg',
extension: 'jpg',
url: 'https://i.ibb.co/c3VRs4x/client1-Bali.jpg'
},
medium: {
filename: 'client1-Bali.jpg',
name: 'client1-Bali',
mime: 'image/jpeg',
extension: 'jpg',
url: 'https://i.ibb.co/1QjB4Fb/client1-Bali.jpg'
},
delete_url: 'https://ibb.co/c3VRs4x/b3072de2f5287a39f81c7dec3cd8a236'
},
success: true,
status: 200
}
Edit: Here is the link to the imgbb API documentation: https://api.imgbb.com/

Imgbb does not allow you to delete images. I just tried going to the delete URL to delete the image and the image got deleted on that page but not on the other links in the JSON. If the functionality is not implemented on the site itself there is no use trying on the API. If they did have the functionality to entirely delete an image then you could have used web scraping to press the buttons.

Related

Strapi: Problem uploading images to strapi, image does not render

Problem
I would like to know if you can help identify the issue related to uploading an image to the thumb field belonging to the content-type Directory.
The image image does not render once it is in the strapi panel, it only shows the name.
const getFileSize = (filePath) => {
return statSync(filePath)["size"]; // statSync from `fs-extra` library
};
strapi.service("api::directory.directory").create({
data: {},
files: {
thumb: {
path: `${imagesDir}/Crab-1-1-scaled.jpg`,
name: "Crab-1-1-scaled.jpeg",
type: mime.lookup(`${imagesDir}/Crab-1-1-scaled.jpg`), // mime from `mime-types` library
size: getFileSize(`${imagesDir}/Crab-1-1-scaled.jpg`),
},
},
});
console.log
size is always zero
{
files: {
thumb: {
path: 'src/scripts/Directory/images/Crab-1-1-scaled.jpg',
name: 'Crab-1-1-scaled.jpeg',
type: 'image/jpeg',
size: 0
}
}
}
output
When uploading the data the image is not rendered, it only shows the name of the image.

Uploading a YouTube Video Using YouTube Data API V3 using Google API Client JavaScript

I visited the Youtube Data v3 API docs to know about how to upload videos using the client library
I got to this page
https://developers.google.com/youtube/v3/docs/videos/insert
but it doesn't seem to explain where to put the video in the request
And Also API explorer just gives the code for request, it doesn't let me execute the code for that page
I also read the resource structure page but didn't find where to put the video
https://developers.google.com/youtube/v3/docs/videos#resource
here's my current code
let req = gapi.client.youtube.videos.insert({
part: 'snippet,status',
snippet: {
title: "Test Video",
description: "Test Description",
categoryId: 28,
defaultLanguage: 'en',
defaultAudioLanguage: 'en'
},
status: {
privacyStatus: "private"
},
});
console.log(req)
try {
req.execute(function (response) {
console.log(response);
});
} catch (e) {
console.error(e);
}
Now, where do I put the video in the request?
do I have to put that as buffer?
I am fetching video from fetch API for uploading via API
and whenever I run the code I get the Error: 400 in the console
code: 400
data: [{…}]
error: {code: 400, data: Array(1), message: 'Request contains an invalid argument.'}
message: "Request contains an invalid argument."
so can you provide a working example of uploading a video using the client library that is fetched from the fetch API
and show to structure the request body when using the client library?
This is the request body I'm using. Code below was taken from this sample script: https://quanticdev.com/articles/automating-my-youtube-uploads-using-nodejs/
In my case I'm uploading an .mp4
auth: auth,
part: 'snippet,status',
requestBody: {
snippet: {
title,
description,
tags,
categoryId: 20,
defaultLanguage: 'en',
defaultAudioLanguage: 'en'
},
status: {
privacyStatus: "public",
selfDeclaredMadeForKids: false
},
},
media: {
body: fs.createReadStream(videoPath),
}

How to send document or images in group using plain javascript pusher chatkit

I have my chat application ready using plain javascript and pusher Chatkit. Now I want to send files or images in chat in the message. how to achieve this feature.
Chatkit has sendMultipartMessage method which allows complex messages(attachment,URL etc).
Example from the docs -
currentUser.sendMultipartMessage({
roomId: myRoom.id,
parts: [
{ type: "text/plain", content: "🐷😍" },
{
type: "image/gif",
url: "https://gfycat.com/failingforkedheterodontosaurus",
},
{
file: document.querySelector("#attach").files[0],
customData: { metadata: 42 },
}
],
});
One tutorial that uses multipartMessaging - https://pusher.com/tutorials/multiple-attachments-chatroom#migrate-to-multipart-messages

Can't create AdCreative using facebook-nodejs-business-sdk module in node js

I am trying upload image using facebook-nodejs-business-sdk. I am getting error which is given below:
{ error:
{ message: 'Invalid parameter',
type: 'OAuthException',
code: 100,
error_subcode: 1443186,
is_transient: false,
error_user_title: 'Image couldn\'t be loaded',
error_user_msg:
'There was a problem while loading your image. Please try uploading the image again or choose a different image.',
fbtrace_id: 'A7_XjnvwsvVzYb0cnCZUXdi' } },
method: 'POST',
url:
'https://graph.facebook.com/v4.0/act_578276446245361/adcreatives?access_token=<access_token_provided>,
data:
{ name: 'Sample Image Upload',
object_story_spec: { page_id: '<page_id>', link_data: {image_hash:<image_hash>,link:'<page_link>','message':'Ad message'} },
id: 'act_<account_id>' } }
I have tried all the images such as .jpg, .png, .bmp, .git. Nothing worked. Any help would be helpful. Thanks. for further doubt or any question comment me or messag me. Thanks.

How can I call Web APIs in React JSX?

I'm writing a music player with React and Electron and want to add metadata for the audio so as I can get MPRIS support. So I did some searching and found Media Session API is what I needed.
To test it, I copied the code from the exmaple code contained by the above link into a function in my project.
navigator.mediaSession.metadata = new MediaMetadata({
title: 'Unforgettable',
artist: 'Nat King Cole',
album: 'The Ultimate Collection (Remastered)',
artwork: [
{ src: 'https://dummyimage.com/96x96', sizes: '96x96', type: 'image/png' },
{ src: 'https://dummyimage.com/128x128', sizes: '128x128', type: 'image/png' },
{ src: 'https://dummyimage.com/192x192', sizes: '192x192', type: 'image/png' },
{ src: 'https://dummyimage.com/256x256', sizes: '256x256', type: 'image/png' },
{ src: 'https://dummyimage.com/384x384', sizes: '384x384', type: 'image/png' },
{ src: 'https://dummyimage.com/512x512', sizes: '512x512', type: 'image/png' },
]
});
I put it into a function that a component will call when the next song is played.However, I got errors like this:
Failed to compile.
./src/components/FM/Cover/index.jsx
Line 112: 'MediaMetadata' is not defined no-undef
Search for the keywords to learn more about each error.
Why?
You need to reference the window object.
window.MediaMetadata
^^^^^^
This is because babel/es-lint does not know MediaMetadata exists and will throw an error. Since Chrome injects this object as a global variable, it is accessible via the window object.
(re-posting what #AngelSalazar said in the comments of the OP for ease of use)

Categories

Resources