Skip to content
v2.7

Get file preview

Get a file preview image.

GET/storage/buckets/{bucketId}/files/{fileId}/previewScope files.read

Get a file preview image. Currently, this method supports preview for image files (jpg, png, and gif), other supported formats, like pdf, docs, slides, and spreadsheets, will return the file icon image. You can also pass query string arguments for cutting and resizing your preview image. Preview is supported only for image files smaller than 10MB.

bucketId string required

Storage bucket unique ID. You can create a new storage bucket using the Storage service server integration.

fileId string required

File ID

width number

Resize preview image width, Pass an integer between 0 to 4000.

height number

Resize preview image height, Pass an integer between 0 to 4000.

gravity ImageGravity

Image crop gravity. Can be one of auto,center,top-left,top,top-right,left,right,bottom-left,bottom,bottom-right Values: auto, center, top-left, top, top-right, left, right, bottom-left, bottom, bottom-right.

quality number

Preview image quality. Pass an integer between 0 to 100. Defaults to keep existing image quality.

borderWidth number

Preview image border in pixels. Pass an integer between 0 to 100. Defaults to 0.

borderColor string

Preview image border color. Use a valid HEX color, no # is needed for prefix.

borderRadius number

Preview image border radius in pixels. Pass an integer between 0 to 4000.

opacity number

Preview image opacity. Only works with images having an alpha channel (like png). Pass a number between 0 to 1.

rotation number

Preview image rotation in degrees. Pass an integer between -360 and 360.

background string

Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.

output ImageFormat

Output format type (jpeg, jpg, png, gif and webp). Values: jpg, jpeg, png, webp, heic, avif, gif.

token string

File token for accessing this file.

Access: API key with the files.read scope or user session, or even no session (the resource’s permissions apply).

200Success
400Invalid or missing parameter
401No session, no permission on the resource or key without the scope
404Resource in the path not found
429Rate limit

Every error comes as JSON with code, type and message: see Errors.

import { Client, Storage, ImageGravity, ImageFormat } from '@owbase/web';
const client = new Client()
.setEndpoint('https://cloud.owbase.dev/v1') // Your API Endpoint
.setProject('<YOUR_PROJECT_ID>'); // Your project ID
const storage = new Storage(client);
const result = storage.getFilePreview({
bucketId: '<BUCKET_ID>',
fileId: '<FILE_ID>',
width: 0, // optional
height: 0, // optional
gravity: ImageGravity.Auto, // optional
quality: -1, // optional
borderWidth: 0, // optional
borderColor: 'FFFFFF', // optional
borderRadius: 0, // optional
opacity: 0, // optional
rotation: -360, // optional
background: 'FFFFFF', // optional
output: ImageFormat.Jpg, // optional
token: '<TOKEN>', // optional
});
console.log(result);
Response200 OK

No response body.


The descriptions on this page come from the server API specification (BSD-3-Clause license), and the examples come from the SDK generator (MIT license). The full notices are in the NOTICE file of the @owbase/web and @owbase/node packages.

Was this page helpful?