File Upload

When source file must be converted multiple times, conversion performance can be increased by uploading file once and converting it multiple times without uploading it once again. Uploaded file will be stored in convertapi.com server for 3 hours and will be accessible just by conversion system. In conversion request file can be referred by the File ID, which will be given after file upload. Another benefit of uploaded file is that conversion request can be formed just by URL query (no need for multipart or json formatters).

File upload request

File upload response content type is controlled by "Accept" header field value. Default "Accept" header field value is "application/json". If request header has "Accept: text/plain" field, response body will contain plain File ID string. This response format is useful when there are no JSON or XML parsers.

application/json

File data must be encoded with Base64 encoding.

File upload example in JSON format
Request:
POST https://v2.convertapi.com/upload
{
    "FileUpload":{
        "FileName": "my_file.doc",
        "FileData": "--Base64 encoded file content--"
    }
}
Response:
{
    "FileId": "LCWS8IGD"
}

multipart/form-data

Each request parameter must be in separate part.

File upload example in form-data format
Request:
POST /upload HTTP/1.1
Host: v2.convertapi.com
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----7MA4YWxkTrZu0gW

------7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="FileData"; filename="my_file.doc"
Content-Type: 

--FILE DATA--
------7MA4YWxkTrZu0gW--
Response:
{
    "FileId": "LCWS8IGD"
}

application/octet-stream

Raw file data upload is most simple and efficient upload type. Must be provided content-disposition header field with the file name.

File upload example in octet-stream format
Request:
POST /upload HTTP/1.1
Host: v2.convertapi.com
Content-Disposition: inline; filename="my_file.doc"
Cache-Control: no-cache

--FILE DATA--
Response:
{
    "FileId": "LCWS8IGD"
}

Upload from remote URL

If file is accessible by the URL, it can be uploaded directly from it's location.

Upload from remote URL example
Request:
POST https://v2.convertapi.com/upload-from-url?url=http%3A%2F%2Fexample.com%2Ffile.doc&FileName=my_file.doc
Response:
{
    "FileId": "LCWS8IGD"
}

Additionally can be provided "HeaderName" and "HeaderValue" parameters, needed for integration with third party systems like Google Drive.

File upload request HTTP response codes

200

Upload completed successfully.

500

Internal codes provided in response body:

  • 5007 - Unable to download remote file.

Actions with the uploaded file

Conversion

Uploaded file conversion example
Request:
GET/POST https://v2.convertapi.com/convert/doc/to/pdf?Secret=XXX&File=LCWS8IGD
Response:
{
    "ConversionTime": 2,
    "Files": [
        {
            "FileName": "my_file.pdf",
            "FileSize": 523672,
            "FileData": "--Base64 encoded file content--"
        }
    ]
}

Delete uploaded file

If file is no longer required it can be deleted.

Example for deleting uploaded file UULJBJER
Request:
DELETE https://v2.convertapi.com/upload/UULJBJER