PUT {presigned url}
Important The presigned URL must be retreived from the /file/upload/get-presigned-url for the PUT operation to succeed.
Content-Type header
When sending PUT request don’t forget to add Content-Type header with proper value based on input file type.
For example:
| File Extension | Content-Type Value |
.txt .csv .xml .json | text/plain |
.pdf | application/pdf |
.msg .eml | application/vnd.ms-outlook |
.doc | application/msword |
If you’re not sure then use application/octet-stream header. It works for most file types.
All uploaded files are treated as temporary files and are automatically permanently removed after 1 hour. If you have a file that you want to reuse over and over, please upload it to PDF.co Built-In Files Storage and get its filetoken:// link that you may reuse inside PDF.co API.
Example Response
To see the main response codes, please refer to the
Response Codes page.
{
"presignedUrl": "https://pdf-temp-files.s3-us-west-2.amazonaws.com/0c72bf56341142ba83c8f98b47f14d62/test.pdf?X-Amz-Expires=900&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIZJDPLX6D7EHVCKA/20200302/us-west-2/s3/aws4_request&X-Amz-Date=20200302T143951Z&X-Amz-SignedHeaders=host&X-Amz-Signature=8650913644b6425ba8d52b78634698e5fc8970157d971a96f0279a64f4ba87fc",
"url": "https://pdf-temp-files.s3-us-west-2.amazonaws.com/0c72bf56341142ba83c8f98b47f14d62/test.pdf?X-Amz-Expires=3600&x-amz-security-token=FwoGZXIvYXdzEGgaDA9KaTOXRjkCdCqSTCKBAW9tReCLk1fVTZBH9exl9VIbP8Gfp1pE9hg6et94IBpNamOaBJ6%2B9Vsa5zxfiddlgA%2BxQ4tpd9gprFAxMzjN7UtjU%2B2gf%2FKbUKc2lfV18D2wXKd1FEhC6kkGJVL5UaoFONG%2Fw2jXfLxe3nCfquMEDo12XzcqIQtNFWXjKPWBkQEvmii4tfTyBTIot4Na%2BAUqkLshH0R7HVKlEBV8btqa0ctBjwzwpWkoU%2BF%2BCtnm8Lm4Eg%3D%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA4NRRSZPHEGHTOA4W/20200302/us-west-2/s3/aws4_request&X-Amz-Date=20200302T143951Z&X-Amz-SignedHeaders=host;x-amz-security-token&X-Amz-Signature=243419ac4a9a315eebc2db72df0817de6a261a684482bbc897f0e7bb5d202bb9",
"error": false,
"status": 200,
"name": "test.pdf",
"remainingCredits": 98145
}
Inconsistent URL Encoding in cURL Output: When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (&) may appear as \u0026 in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you’re parsing the response programmatically, your JSON parser will handle this conversion automatically.
Code Samples
CURL
JavaScript/Node.js
Python
PHP
curl --location --request PUT '<insert presignedUrl here>'
--header 'x-api-key: YOUR_API_KEY'
--header 'Content-Type: application/octet-stream'
--data-binary '@./sample.pdf'
function uploadFile(apiKey, localFile, uploadFileUrl) {
return new Promise(resolve => {
fs.readFile(localFile, (err, data) => {
request({
method: "PUT",
url: uploadFileUrl,
body: data,
headers: {
"Content-Type": "application/octet-stream",
"x-api-key": apiKey
}
}, (err, res, body) => {
if (!err) {
resolve();
}
else {
console.log("uploadFile() request error: " + err);
}
});
});
});
}
uploadFileUrl = "file URL retrieved from /file/upload/get-presigned-url"
with open(fileName, 'rb') as file:
requests.put(uploadFileUrl, data=file, headers={"x-api-key": API_KEY, "content-type": "application/octet-stream"})
<?php
$uploadFileUrl = "file URL retrieved from /file/upload/get-presigned-url";
$localFile = $_FILES["fileInput"]["tmp_name"];
$fileHandle = fopen($localFile, "r");
curl_setopt($curl, CURLOPT_URL, $uploadFileUrl);
curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: " . $apiKey, "content-type: application/octet-stream"));
curl_setopt($curl, CURLOPT_PUT, true);
curl_setopt($curl, CURLOPT_INFILE, $fileHandle);
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($localFile));
// Execute request
curl_exec($curl);
fclose($fileHandle);
?>