Get an image if passes query parameters to a PDF URL

Hello,

It’s funny to detect if you append query parameters to a PDF URL, the server responses with an image instead of the PDF file. Well funny until you get an email saying this URL is in the newsletter you just sent :frowning:

Here without query parameters, gets the PDF

Here with two o more query parameters, get an image

It is a bug? Or it is possible to avoid it?

Thank you :slight_smile:

Hello @mordonez.sanchez

As you said, every file that goes through Imgix (if you pass any parameters) is returned as an image.
As an example, if i have a sample PDF https://www.datocms-assets.com/82186/1664800813-sample.pdf and i want to restrict its width to 500, it will have to become an image: https://www.datocms-assets.com/82186/1664800813-sample.pdf?w=500

Can you share with us your use-case for the imgix parameters for PDFs?

My problem is with redirects 30x to the static urls.

I have an intermediate tracking endpoint that counts the access, downloads, etc … of some assets. And when I perform the redirection towards the file the params are transfer as well, and PDF urls returns an image as in the example

@mordonez.sanchez i see, unfortunately we can’t do much about this as when you pass those parameters, IMGIX interprets that the file should be rasterised into an image, and have the transformations applied on that image, which are valid uses for the parameters in a PDF file.

So the only way to fix this would be to not pass the parameters in your intermediary endpoints, if you don’t want them to be applied in the file.

1 Like

Thank’s @m.finamor for the support.

It was my first approach , but in Netlify where I host the project when I do a redirect in a netlify function always pass the query params to the Location :sweat_smile: Disable Netlify passing query params on 302 redirect - Support - Netlify Support Forums

  return {
    statusCode: 302,
    headers: {
      "Location": assetUrl ,
    },
  };

If helps to another, my solution finally was to override the asset url with a custom query param like “?view” at the end :expressionless:

  return {
    statusCode: 302,
    headers: {
      "Location": assetUrl + '?view',
    },
  };

Thanks!!

1 Like