node-s3-uploader icon indicating copy to clipboard operation
node-s3-uploader copied to clipboard

Handle image paths without extension when uploading

Open Starefossen opened this issue 8 years ago • 7 comments

Some files does not have an extension (latest version of expressjs/multer for instance) which crates a problem for s3-uploader. We should add the ability to pass inn one of the following:

a) the original file name b) file extension b) image mime type

client.upload('/some/file', { mime: "image/jpeg" }, function(err, versions, meta) {
  ...
});

Starefossen avatar Jul 29 '15 06:07 Starefossen

Wouldn't it be better to always detect file format instead since mime type/extensions can be wrong? Seems like identify could help with this.

oblador avatar Aug 21 '15 15:08 oblador

Good suggestion @oblador, that would definitely be the best option. Would require some more change too I think.

Starefossen avatar Aug 21 '15 19:08 Starefossen

Just tested this and this does not seem to be problem at first sight. My test was a jpg, without an extension, used as input for s3-uploader.

anthonyringoet avatar Nov 14 '15 20:11 anthonyringoet

What did the final URL result in for the original and for a resized image look like?

I thought this line assumed that the original image file name has a file extension.

Starefossen avatar Nov 14 '15 21:11 Starefossen

Well, some of the results have an extension, some do not. So it's a good idea to improve the handling :)

anthonyringoet avatar Nov 14 '15 21:11 anthonyringoet

I just looked into the problem again and remembered that this is not as straight forward as it looked like at first glance since each resized image version may have it's own format (versions[#].format).

We are passing the entire image metadata into resize() which contains the source image format (results.metadata.format). I have created Turistforeningen/node-im-resize#8 which makes use of this to make sure that all resized image versions gets a propper file extension.

We have to do something similar here to make sure that the original image gets a correct file extension as well.

Starefossen avatar Nov 14 '15 22:11 Starefossen

Anyone have a working solution?

johnrickman avatar Apr 29 '16 19:04 johnrickman