Get Basic Thumbnail
Get Basic Thumbnail
A thumbnail is a small image, either as .png
or as .jpg
that can be used in
an application as a representation of the file, for example as a placeholder for
a link that downloads or previews the file.
An alternative way to get a thumbnail for a file is using the representations API.
Requesting
To request a file thumbnail use the GET /files/:id/thumbnail.:extension
endpoint.
curl -X GET https://api.box.com/2.0/files/12345/thumbnail.png \
-H 'Authorization: Bearer <ACCESS_TOKEN>'
Stream thumbnailContents = await client.FilesManager.GetThumbnailAsync("11111", maxWidth: 160, maxHeight: 160);
// Get a thumbnail with size exactly 256x256
BoxFile file = new BoxFile(api, "id");
byte[] thumbnail = file.getThumbnail(BoxFile.ThumbnailFileType.PNG, 256, 256, 256, 256)
file_id = '11111'
thumbnail = client.file(file_id).get_thumbnail(extension='jpg')
client.files.getThumbnail('12345')
.then(thumbnailInfo => {
if (thumbnailInfo.location) {
// fetch thumbnail from location URL
} else if (thumbnailInfo.file) {
// use response.file Buffer contents as thumbnail
} else {
// no thumbnail available
}
});
client.files.getThumbnail(forFile: "11111", extension: .png) { (result: Result<Data, BoxSDKError>) in
guard case let .success(thumbnailData) = result else {
print("Error getting file thumbnail")
return
}
let thumbnailImage = UIImage(data: thumbnailData)
}
When a thumbnail was successfully created, this will return the thumbnail in the body of the response as binary data.
Asynchronous thumbnail creation
Sometimes the thumbnail can not be created directly. Instead, the API will
return a HTTP 202
with a location
response header. The location
is for a temporary image that can be used while the thumbnail is being
generated.
A retry-after
response header is also provided to present you with
an estimated amount of seconds before retrying this endpoint.
Supported file sizes
The following formats and sizes of thumbnails are available.
File Type | Dimensions |
---|---|
JPG | 32x32 , 94x94 , 160x160 , 320x320 , 1024x1024 , 2048x2048 * |
PNG | 1024x1024 *, 2048x2048 * |
Some restrictions apply to the sizes marked as *
.
File size restrictions
Original file size
Thumbnails are not scaled up. If the original file size of the file uploaded to Box is smaller than the representation dimensions, the resulting thumbnail is capped at the size of the original file.
Supported file types
At this time the following file types are supported.
File Type | File Extensions |
---|---|
Documents | doc , docx , gdoc , gsheet , gslide , gslides , odp , ods , odt , pdf , ppt , pptx , rtf , wpd , xls , xlsm , xlsx , key , pages , numbers |
Images | ai , bmp , gif , eps , jpeg , jpg , png , ps , psd , svg , tif , tiff , dcm , dicm , svs , tga |
Audio | aac , aifc , aiff , amr , au , flac , m4a , mp3 , ogg , ra , wav , wma |
Video | 3g2 , 3gp , avi , m2v , m2ts , m4v , mkv , mov , mp4 , mpeg , mpg , ogg , mts , qt , wmv |