Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension is missing when fetching image from an URL with redirect #227

Open
Betree opened this issue Nov 2, 2017 · 2 comments
Open

Extension is missing when fetching image from an URL with redirect #227

Betree opened this issue Nov 2, 2017 · 2 comments

Comments

@Betree
Copy link

Betree commented Nov 2, 2017

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
Copy link
Author

Betree commented Nov 4, 2017

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

@sebastialonso
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants