File is damaged after uploading into PDF.co via presigned url
It means that the file was damaged during the upload process. The most common reason is the use of incorrect Content-Type
header.
If you use PUT
to upload file then you must add the Content-Type
header as application/octet-stream
!
Do not use multipart/form-data
for uploading file into a presigned link in PDF.co!
Incorrect
function uploadFile(file){
...
const formData = new FormData();
formData.append("file", file);
await axios({
method: 'PUT',
url,
data: formData,
headers: {'Content-Type': 'multipart/form-data'}
})
...
}
Correct (for PDF files)
function uploadFile(file){
...
// upload file data directly
// [https://github.com/axios/axios#axiospatchurl-data-config](https://github.com/axios/axios#axiospatchurl-data-config)
await axios({
method: 'PUT',
url: url,
data: file,
headers: {'Content-Type': 'application/pdf'}
})
...
}
Correct (for non-PDF files like images or documents)
function uploadFile(file){
...
// upload file data directly
// [https://github.com/axios/axios#axiospatchurl-data-config](https://github.com/axios/axios#axiospatchurl-data-config)
await axios({
method: 'PUT',
url: url,
data: file,
headers: {'Content-Type': 'application/octet-stream'}
})
...
}