Generate File Previews API - ApyHub

Generate File Preview API

ApyHub
ApyHub
verified icon
300 atoms
Base tier

About

Convert documents and media files into preview images using this file preview API. Upload files in formats like PDF, DOCX, PPTX, XLSX, TXT, and more to generate resized preview images by specifying optional width and height.
This API is designed for developers building document management systems, cloud storage platforms, file sharing tools, or web and mobile applications that need fast, lightweight visual previews. It helps reduce bandwidth usage, improve loading times, and enhance performance in mobile or low-connectivity environments.
Use it for PDF to image conversion, Word document previews, PowerPoint slide thumbnails, and other scenarios where a visual snapshot of a file improves usability.
Try the Generate File Preview API for free in the ApyHub playground to simplify preview generation and improve file-handling workflows.
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 when 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.
Table of contents
AboutAPI PlaygroundAPI DocumentationAuthenticationError codesRelated Utility APIsRelated Articles