Closed jacobtomlinson closed 8 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...
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.
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
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.
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?
@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.
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?
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!
I have implemented this in #8 :smile:
should be fixed now, please try 1.4.0
on npm
All files show up as
application/octet-stream
in S3.This should be set to the actual content type of the file.