Skip to content

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

@Betree

Description

@Betree

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions