Link Search Menu Expand Document

Uploaded PDF is downloaded as attachment but ned to be inline to auto-display in pdf viewer in a browser

By default files and documents uploaded to PDF.co temp storage are downloaded as attachments. If you need to upload and make it accessible as inline (to display in a browser preview, for example) then you need to do the following:

  1. REQUIRED: When calling file/upload/get-presigned-url Add ContentType parameter with application/pdf value
  2. REQUIRED: When uploading this file via PUT http method, set Content-Type http header (NOT parameter!)

Hint: if you use Postman for testing then please be aware it inserts automatically generated hidden http headers including Content-Type header.

Hint 2: got SignatureDoesNotMatch error when uploading PUT? To fix it, please verify if you are setting Content-Type header to the same value as it was for ContentType param for /file/upload/get-presigned-url.

IMPORTANT: 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'}
        })
...
}