基本的なサムネイルの取得
基本的なサムネイルの取得
サムネイルとは小さい画像のことで、アプリケーション内でファイルのレプリゼンテーションとして使用できる.png
または.jpg
で表されます。たとえば、ファイルをダウンロードまたはプレビューするリンクのプレースホルダとして使用されます。
ファイルのサムネイルは、レプリゼンテーションAPIを使用して取得することもできます。
リクエスト
ファイルのサムネイルをリクエストするには、GET /files/:id/thumbnail.:extension
エンドポイントを使用します。
cURL
curl -X GET https://api.box.com/2.0/files/12345/thumbnail.png \
-H 'Authorization: Bearer <ACCESS_TOKEN>'
.NET
Stream thumbnailContents = await client.FilesManager.GetThumbnailAsync("11111", maxWidth: 160, maxHeight: 160);
Java
// Get a thumbnail with size exactly 256x256
BoxFile file = new BoxFile(api, "id");
byte[] thumbnail = file.getThumbnail(BoxFile.ThumbnailFileType.PNG, 256, 256, 256, 256)
Python
file_id = '11111'
thumbnail = client.file(file_id).get_thumbnail(extension='jpg')
Node
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
}
});
iOS
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)
}
サムネイルの作成に成功すると、そのサムネイルが応答の本文内でバイナリデータとして返されます。
サムネイルの非同期的な作成
場合によっては、サムネイルを直接作成できないこともあります。代わりに、APIからlocation
応答ヘッダーでHTTP 202
が返されます。この場所は、サムネイルの生成中に使用できる一時的な画像のためのものです。
このエンドポイントを再試行するまでの推定秒数を示すretry-after
応答ヘッダーも返されます。
サポートされているファイルサイズ
以下のサムネイルの形式とサイズが使用可能です。
ファイルタイプ | サイズ |
---|---|
JPG | 32x32 , 94x94 , 160x160 , 320x320 , 1024x1024 , 2048x2048 * |
PNG | 1024x1024 *, 2048x2048 * |
*
が付いているサイズには、いくつかの制限があります。
ファイルサイズの制限
元のファイルサイズ
サムネイルは拡大されません。Boxにアップロードされたファイルの元のファイルサイズがレプリゼンテーションのサイズより小さい場合は、作成されるサムネイルのサイズの上限は元のファイルのサイズになります。
サポートされているファイルタイプ
現時点でサポートされているファイルタイプは以下のとおりです。
ファイルタイプ | ファイル拡張子 |
---|---|
ドキュメント | doc , docx , gdoc , gsheet , gslide , gslides , odp , ods , odt , pdf , ppt , pptx , rtf , wpd , xls , xlsm , xlsx , key , pages , numbers |
画像 | ai , bmp , gif , eps , jpeg , jpg , png , ps , psd , svg , tif , tiff , dcm , dicm , svs , tga |
オーディオ | aac , aifc , aiff , amr , au , flac , m4a , mp3 , ogg , ra , wav , wma |
動画 | 3g2 , 3gp , avi , m2v , m2ts , m4v , mkv , mov , mp4 , mpeg , mpg , ogg , mts , qt , wmv |