File is damaged after uploading into PDF.co via presigned url

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

function uploadFile(file){
...
        // upload file data directly
        // https://github.com/axios/axios#axiospatchurl-data-config
        await axios({
            method: 'PUT',
            url: url,
            data: file,
            headers: {'Content-Type': 'application/octet-stream'}
        })
...
}
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.