Reputation: 7
I'm currently trying to send an image through JDA but can't get it to work. The only thing I can find on Google is the addFile (java.io.File) method, which is no longer available in the most recent version of JDA. I am currently struggling to find a solution using the addFiles() method.
This is my current attempt.
byte[] buffer = ((DataBufferByte)(img).getRaster().getDataBuffer()).getData();
FileUpload upload = new FileUpload(new ByteArrayInputStream(buffer));
c.sendMessage("Image:").addFiles(upload).complete();
I am getting this error message in my IDE, but I don't know what to make of it.
thanks guys.
Upvotes: 1
Views: 1011
Reputation: 6131
You have to use the factory method FileUpload.fromData:
FileUpload upload = FileUpload.fromData(buffer, "image.png");
Make sure you properly encode the image to something like JPG
or PNG
, otherwise this will not work.
Upvotes: 0