quaternionmedia/alfred

fix api download media

mrharpo opened this issue · 2 comments

Currently, download fails under any of the following conditions:

  • the url does not contain it's proper extension (i.e. .mp4, .jpg, .png etc.)
  • if unsafe characters appear in the url, they will be stored in the filename.
  • If two files are downloaded with the same name, they will overwrite each other.

Possible solutions:

  • use Content-Disposition to identify file types
  • save filenames as a url hash

Fixed by pre fetching HEAD request to get headers and determine Content-Type

Works if Content-Type is one of: ['image/jpeg', 'video/mp4', 'image/png', 'audio/mpeg']

Saved filename is uuid.uuid4() + . + ext

Better file naming structure with upstream commit quaternionmedia/otto@fb1988e

filename = '{sha256(url)} + {ext}'