anacronw / multer-s3

multer storage engine for amazon s3
MIT License
660 stars 191 forks source link

Default content type wrong #7

Closed jacobtomlinson closed 8 years ago

jacobtomlinson commented 9 years ago

All files show up as application/octet-stream in S3.

This should be set to the actual content type of the file.

LinusU commented 9 years ago

This is actually not that straight forward. I don't know if it's a good idea to pass on the content-type from the client since that can be set to anything.

Maybe we should provide a contentType: function (req, file, cb) option that behaves like filename?

I think it might be wise to keep the default at application/octet-stream thought...

jacobtomlinson commented 9 years ago

Yes a contentType function could be good.

The trouble with application/octet-stream is that when images are opened in the browser they are downloaded automatically instead of being displayed.

anacronw commented 9 years ago

A contentType function could be overkill. The middleware should be used per-route and you should know the content type from there I think.

I suppose, however, uploading images(gif, jpeg, png etc.) could conceivably be one route.

I agree - the default should stay application/octet-stream

jacobtomlinson commented 9 years ago

You might be right about a whole function being overkill but for my use case I'm afraid it is necessary for the content type to be set correctly.

I can add the functionality to my fork easily enough but it would be nice if this could be dealt with in the main project.

romain10009 commented 9 years ago

Yes me too. I'm uploading pictures. So i'd like to set the content type accordingly. Also i would like to set the Acl so that files are viewable immediately. I use ng file upload. Is there any way to make this work or do i have to use the aws plugin?

anacronw commented 9 years ago

@romain10009 ACL's currently not supported, but if you can try signing an s3 url with TTL for viewing it immediately.

@LinusU There seems to be some npm modules that deal w/ images and video mime detection of streams/buffers:

https://www.npmjs.com/package/image-type https://www.npmjs.com/package/is-mime

Certainly..covering all the random stuff people can upload to s3 isn't feasible, but image and video content seem doable and might cover most cases.

rightaway commented 8 years ago

In the absence of a contentType function can you suggest any workaround for how I could set an appropriate content type on a file before uploading to S3?

https://www.npmjs.com/package/image-type https://www.npmjs.com/package/is-mime

These packages determine what the content type of the file is, but how can I set it on the file itself before/while it's being uploaded?

anacronw commented 8 years ago

Currently there's no way to support this. Those other libraries I was suggesting would be used internally to determine the content type. I can try putting in some support for this this week

PR's welcome!

LinusU commented 8 years ago

I have implemented this in #8 :smile:

anacronw commented 8 years ago

should be fixed now, please try 1.4.0 on npm