apyhub-logo

Generate File Preview API

300 atoms
Base tier

About

This Utility API creates a preview image for a diverse range of file formats.
It accepts a source file and specific dimensions (height and width) to generate a compact and resized preview of the original file.
File previews serve as a versatile solution, catering to various applications by optimizing the visual experience and enhancing overall performance. Whether for web or mobile applications, the generated previews offer a practical way to conserve bandwidth, especially in scenarios with limited or slower network connections.
Select API Endpoints
Input
Output

API Playground

API Documentation

upload file: download file
POST
https://api.apyhub.com/generate/preview/file

Request example

1
curl --location --request POST 'https://api.apyhub.com/generate/preview/file?output=test-sample' \
2
--header 'apy-token: {{token}}' \
3
--form 'file=@"test.pdf"'
The method enables you to submit a file and receive the corresponding file-preview as an image. This straightforward approach allows you to pass a file and obtain the generated file-preview in the response.
Method: POST
Content Type: multipart/form-data
Query Parameter(s)
AttributeTypeMandatoryDescription
outputStringNoThe name of the preview image file. If no output attribute is provided, the default file name will be output.png
widthIntegerNoThe preferred width for the image preview, specified in pixels. For example, the input might be width : 500, with a default value of 840.
heightIntegerNoThe preferred height for the image preview, specified in pixels. For example, the input might be height : 500 . The default height is adjusted proportionally in accordance with the original image's aspect ratio of width.
auto_orientationBooleanNoIf auto_orientation is set to true, it will enable the API to read the Exif data (if available) and automatically rotate the image based on the orientation information in the Exif metadata, by default it is false.
timeIntegerNoThe timestamp in seconds at which you wish to generate the preview, exclusively for video files. For instance, if a video spans 3 minutes and you want to generate a preview at the 90th second, the input would be time: 90. The default is 1, indicating the generation of a preview at the first second of the video.
pageIntegerNoThe document page you wish to generate a preview for, applicable only to textual file types ,such as docx, pdf, ppt, xlsx, etc. For instance, the input could be page: 9, with a default value of 1.
Request Body
AttributeTypeMandatoryDescription
fileFileYesThe source file can be of any type, such as video, audio, image, document, spreadsheet, and more. Regardless of the file type, this service accommodates a wide range of formats for seamless processing, providing a default image in cases where generating a file preview is not feasible for the given format

HTTP Response Codes

The method may return one of the following HTTP status codes:
Status CodeDescription
200The request was successful.
400Request is invalid or file is not accessible.
401Required authentication information is either missing or not valid for the resource.
500There was an error in processing this request.

Authentication

All API requests to ApyHub services need to be authenticated. Currently we support tokens or basic authentication mechanisms. You can generate and view your existing credentials from your workspace settings (on the left side of the navbar) and go to “API Keys".
Points to note:
  • Credential secrets are generated on the fly and are not stored in plain text, so on generating a credential please save the secrets somewhere safe.
  • Use the apy-token as the header parameter to pass the token.
  • Use the Authorization header to send the basic authentication credentials.

Error codes

1
{
2
"error": {
3
"code": 105,
4
"message": "Invalid URL"
5
}
6
}
To search for a specific error code, enter the code in the search box below. Alternatively, you can click on the button to view a complete list of all error codes.