arc icon indicating copy to clipboard operation
arc copied to clipboard

Extension is missing when fetching image from an URL with redirect

Open Betree opened this issue 8 years ago • 2 comments

When fetching pictures from URLs like https://graph.facebook.com/xxxxxxxxxxx/picture?type=normal Arc generates a temporary filename before fetching the file and being redirected. This results in storing a file without extension that won't pass any validate/1 function checking for .jpg:

%Arc.File{
  binary: nil,
  file_name: "picture", # Filename doesn't have extension
  path: "/tmp/O6SQYBCY6ER62AB6SRO72B2RVKXDEGZX"
}

Though HTTPoison doesn't allows us to access redirected URL yet (seet this issue), there's still something we can do.

HTTPoison response for previous URL looks like this:

 %HTTPoison.Response{
  body: <<...>>,
  headers: [{"Last-Modified", "Wed, 14 Jun 2017 00:42:01 GMT"},
    {"Content-Type", "image/jpeg"}, # <= We could use this
    {"Timing-Allow-Origin", "*"},
    {"Access-Control-Allow-Origin", "*"},
    {"Expires", "Thu, 16 Nov 2017 19:58:43 GMT"},
    {"Cache-Control", "max-age=1209600, no-transform"},
    {"Date", "Thu, 02 Nov 2017 20:27:53 GMT"}, {"Connection", "keep-alive"},
    {"Content-Length", "3228"}], 
  status_code: 200
}

We could pattern match the {"Content-Type", "image/jpeg"} header to manually add extension to the file if missing after fetching.

Please tell me what you think of this solution so I can start working on a pull request.

Betree avatar Nov 02 '17 20:11 Betree

Actually #153 seems like a possible fix for my use case and looks pretty simple.

Betree avatar Nov 04 '17 09:11 Betree

Same thing happening to me. PDF or Excel files won't show their extension if uploaded to AWS

sebastialonso avatar Aug 16 '18 18:08 sebastialonso