Thursday, 22 August 2019

Rails Active Storage prevents upload when mime type is empty

I'm uploading a file using Direct Upload and Active Storage in Rails 6. When uploading a .stl file I am met with the following error Mime::Type::InvalidMimeType ("" is not a valid MIME type) which results in a 406 error.

When checking the file with JS it does also not return a Mime type. The file type is simply empty.

This is the case for all .stl files I've tried. Image files work as expected.

I've added the correct Mimetype to a rails initializer using Mime::Type.register "model/stl", :stl. But of course this makes no difference.

The file is submitted in JS using DirectUpload.

  new DirectUpload(file, url, this)

There is no file validation.

So essentially my questions are;

  • Why is the mimetype empty?
  • Is there a different way of verifying the filetype?
  • Can I somehow set the mimetype without causing security issues?
  • Can I somehow accept the file anyway, even if the mimetype is empty?


from Rails Active Storage prevents upload when mime type is empty

No comments:

Post a Comment