theobarberbany/s3_signed_url_server

*nix vs Windows: MIME type issues

Opened this issue · 2 comments

Currently the server guesses the file type based off of the extension of the filename provided using mimetypes.guess_type().

This works on *nix systems where MIME types are sensibly all the same, however for CSV files, on windows the type is not text/csv but application/vnd.ms-excel. This causes the S3 server to reject the file being sent, as the header of the PUT Request sends a type that does not match the type expected by the signed URL.

The server should be rewritten so it takes a PUT, of the file to go into the S3 bucket, and then generates the URL Internally and then uploads it to the bucket (or does so by some other means), returning a pass / fail response.

This reduces the S3 upload to one atomic step, instead of a request and a put.

This is because guessing / attempting to control headers from multiple clients not under my control is not fun, and probably a bad idea, and S3 won't accept any PUT request with headers that don't match those passed when the URL is generated.

Another possibility may be upgrading to boto3, and using the following different method with a POST

http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.generate_presigned_post