Closed jasonleibowitz closed 9 years ago
Hi - looks good
Can you add tests and remove the console.logs?
Actually, how would you both feel about modelling it the same as the builtin DiskStorage
? Let the filename
be a function that receives (req, file, cb)
and that calls the callback with the appropriate name.
That way I think that we provide the most flexibility. On top of this, the possibilities that you mentioned are easily implemented:
function getFilename (req, file, cb) {
cb(null, file.originalname)
}
function getFilename (req, file, cb) {
cb(null, 'my-static-name')
}
function getFilename (req, file, cb) {
crypto.pseudoRandomBytes(16, function (err, raw) {
cb(err, err ? undefined : raw.toString('hex'))
})
}
I agree with @LinusU. This should be consistent with the DiskStorage
method. It would be great to get this in as this is currently stopping me form using this library.
Closing for PR #6 to match DiskStorage
functionality
Hey, I used this module in a recent project and found I needed to modify it because it didn't provide many options when it came to custom filenames. I added a few additional options that I think some people may find helpful. I also updated the readme as well.
The three additional options that can be used when calling the multer-s3 module in app.js are
originalname
,filename
, andcrypto
. I explain each in more detail in the readme, but the basic idea is that if you want to upload the file with the same name as the original file, addoriginalname: true
. If you want to have one filename that is constantly overwritten, like a temporary file, then use filename with a string. Otherwise, the original crypto name you made is the default.