Package net.dv8tion.jda.api.utils
Class NamedAttachmentProxy
java.lang.Object
net.dv8tion.jda.api.utils.FileProxy
net.dv8tion.jda.api.utils.AttachmentProxy
net.dv8tion.jda.api.utils.NamedAttachmentProxy
A utility class to retrieve attachments.
This supports downloading the images from the normal URL, as well as downloading the image with a specific width and height.
This supports downloading the images from the normal URL, as well as downloading the image with a specific width and height.
This is a specialization of AttachmentProxy
, which is aware of the file name of the attachment.
-
Constructor Summary
ConstructorsConstructorDescriptionNamedAttachmentProxy
(String url, String fileName) Constructs a newAttachmentProxy
for the provided URL. -
Method Summary
Modifier and TypeMethodDescriptiondownloadAsFileUpload
(int width, int height) Returns aFileUpload
which supplies a data stream of this attachment, with the original attachment's file name and at the specified size.The file name of the attachment.Methods inherited from class net.dv8tion.jda.api.utils.AttachmentProxy
download, downloadAsFileUpload, downloadAsIcon, downloadAsIcon, downloadToFile, downloadToPath, downloadToPath, getUrl, withClient
Methods inherited from class net.dv8tion.jda.api.utils.FileProxy
download, downloadAsFileUpload, downloadToFile, downloadToPath, downloadToPath, getUrl, setDefaultHttpClient
-
Constructor Details
-
NamedAttachmentProxy
Constructs a newAttachmentProxy
for the provided URL.- Parameters:
url
- The URL to download the attachment fromfileName
- An optional file name fordownloadAsFileUpload(int, int)
- Throws:
IllegalArgumentException
- If the provided URL is null
-
-
Method Details
-
getFileName
The file name of the attachment.- Returns:
- The file name
-
downloadAsFileUpload
Returns aFileUpload
which supplies a data stream of this attachment, with the original attachment's file name and at the specified size.
The returnedFileUpload
can be reused safely, and does not need to be closed.The attachment, if an image, may be resized at any size, however if the size does not fit the ratio of the image, then it will be cropped as to fit the target size.
If the attachment is not an image then the size parameters are ignored and the file is downloaded.- Parameters:
width
- The width of this image, must be positiveheight
- The height of this image, must be positive- Returns:
FileUpload
from this attachment.- Throws:
IllegalArgumentException
- If any of the follow checks are true- The requested width is negative or 0
- The requested height is negative or 0
-