Why is my image in the rich embed not loading - discord.js

My code:
client.on('message', message => {
if (message.content.startsWith(prefix + "birb")) {
const embed = new Discord.RichEmbed()
.setColor(0x9370db)
.setAuthor("ModularBot: Birb", "https://i.imgur.com/Y9HlaCp.png")
.setImage("https://random.birb.pw/tweet/random")
.setFooter("Powered by random.birb.pw")
.setTimestamp()
message.channel.send({embed})
}
});
Whenever I do that the image just appears blank with nothing in it

Discord requires you to send the actual file, not just a URL from the file. So, in your setImage line, you need to be sending the direct link for the file, such as https://random.birb.pw/tweet/random/1.png , or whatever the file name is called.

Discord seems to require image links to be suffixed by an image file extension. I've only tested .png myself, but if there is no file extension, Discord assumes that the url is incorrect and ignores it to save computing time and space, as their servers keep a local copy of each image sent.

Like previous replies said, Discord needs an image file. You can use snekfetch or superagent to fetch the image from the API and then send the file.

Just figured out a thing. Even if you succeed in creating a REST API that can output a file when anybody ping the API, wich is what I did, Discord won't accept any image that is not from a DNS server. So you can put images from a website with a DNS name, like https://api.twitter.com/ , but not from any IP, not yours nor anyone's.

I solved that problem by adding www to all my image urls.
Maybe it was an issue with my server?
My app is React with next.js and I'm hosted at Vercel.

Related

Showing pictures that uploaded on express server on react in a correct way

I built an express API and uploading images with multer .
in DB I save a post with image's name and I combine it with API link and show it in this way.
enter image description here
but my problem is , I think this is not a good way to show uploaded pictures and users can see API link ، isn't it bad? i mean in a security issues
can you help me please.
No, this really isn't an issue. There isn't any problem with people knowing your API URL. If someone uses something like postman to intercept the request, they'll find it out either way. You should however secure your API if there is important data on it.

Extracting zipped images from utf-8 encoded reponse of a rest api call and displaying those images to user in react without downloading

I have a zipped file containing images which I am sending as response to a python REST API call. I want to create a rest application which consumes the python rest api in this manner: The response's content should be extracted without downloading (in browser side) and all the images should be displayed to the user. Is this possible? If yes, could you please help me in the implementation? I am unable to find help anywhere.
I think what you are trying to do is have a backend server (python) where zip files of images are hosted. You need to create an application (that could be in react) that
Send HTTP calls to the server get those .zip files.
Unzip them. How to unzip file on javascript
Display the images to the user. https://medium.com/better-programming/how-to-display-images-in-react-dfe22a66d5e7
I'm not sure what utf-8 has to do with this, but this is possible. A quick google gave me the results above.

How can i get the blob type of the uploaded file?

I trying to upload a picture from my mobile app for which i am using codenameone multipart request every thing is coming fine to my webservice method call but while i trying to convert coming string filepath to File type its showing me FileNotFound Exception (note: as i am uploading my file from a mobile device and not from my local machine its working fine in my local machine because it getting the path here).I need the File type so that i can convert it into FileInputStream to store the BLOB type in my database.
So, can you please give a hint to resolve my issue.
Thanks in Advance.
See this sample of an image upload servlet that accepts an image from the client. This is discussed in depth in this course on Udemy.
As you can see the path is something that's useful for your reference not for reading the file. You need to get the blob data of the file and use that to read the uploaded file.

The name of a created PDF is not transferred from the server to the client (GWT - GAE)

I develope a GWT-application which creates a PDF-file at the server, and then transferres it to the client.
At the client-side, a window appears which allows the user either to
open it with a program assigned to the file name ending, or
save it to disc.
I have read several threads to this topic, such as
How can a user download a file in client side (Google Web Toolkit)
GWT: Showing PDF created as POST response
How can a user download a file in client side (Google Web Toolkit)
and that helped me coding the doGet()-methode in my print-servlet like this:
resp.setContentType("application/octet-stream");
resp.setHeader("Content-Disposition:", "attachment; filename=\"" + fileName + "\"");
This works fine when testing and debugging using the local GWT-developement server.
But my big problem is:
After deploying to GAE and running the code on GAE, the created pdf-name is not transferred to the client...!
Instead of e.g. TestPdf-25072016.pdf, the name only consists of the word print.
This leads to the fact that the standard-program for a PDF is not invoked automatically when I want to open it. And, of course, print is not the name of the PDF I want to have...
Where is my failure? Especially I am confused that everything works fine when using the local developement server?
Thanks a lot for your support!
You could use a tool like Wireshark or Fiddler to capture the actual HTTP header sent to you when you call printing in GAE.
Maybe GAE is adjusting the header or just blocking it.

how do i rename file using loopback storage service

I am stuck how to rename the uploaded file to server.
don't know how to rename the file and send that url further.
Using [loopback-storage-service]
Do i make changes in container model?
Help is appreciated.
To rename create a file inside your loopback boot folder
boot/renameFile.js
module.exports = function(app) {
//Function for checking the file type..
app.dataSources.presImage.connector.getFilename = function(file, req, res) {
//Return the new FileName
return 'NEW_FILENAME.JPG'
}
}//exports
I checked the angular-file-upload's github page, it says
Angular File Upload is a module for the AngularJS framework. Supports drag-n-drop upload, upload progress, validation filters and a file upload queue. It supports native HTML5 uploads, but degrades to a legacy iframe upload method for older browsers. Works with any server side platform which supports standard HTML form uploads.
I also checked angular-file-upload.js, there is no provision for renaming in it.
I would recommend to upload the file first and then using your server side code rename it for you, it will be easier that way.
Update : Found this on its github issues - Is it possible to rename the file before upload?

Resources