cozy / cozy-client-js

Javascript library to write Cozy applications
https://docs.cozy.io/en/cozy-client-js/README/
MIT License
11 stars 12 forks source link

Default content-type depending on extension #197

Closed ptbrowne closed 6 years ago

ptbrowne commented 7 years ago

In application code (ACH), I see :

  switch (fileJSON.extension) {
    case '.jpg':
    case '.jpeg':
    case '.gif':
    case '.png':
    case '.tiff':
      contentType = `image/${fileJSON.extension.substring(1)}`
      break
    case '.pdf':
      contentType = `application/pdf`
      break
    default:
      contentType = ''
      break
  }
...
client.files.create(

I think it should be the responsibility of client.files.create to do that.

nono commented 7 years ago

I don't think it's the right way to do that. Browsers fill automatically the content-type when uploading a file. For nodejs stuff (like ACH), we can rely on packages like mime.

ptbrowne commented 7 years ago

Yes I think we should rely on mime to do that. But still I think it should be the responsibility of cozy-client-js to do that (with the help of mime).