keystonejs / keystone-storage-adapter-s3

⚠️ Archived - Legacy S3 Storage Adapter for KeystoneJS
MIT License
17 stars 55 forks source link

No option to use original filename #11

Open mhoffmeyerDC opened 8 years ago

mhoffmeyerDC commented 8 years ago

It looks like the generateFilename function is set to nameFunctions.randomFilename - meaning any upload using this storage adapter will always have a random name.

Suggest adding an option to allow the original name to be used instead.

Concept:

    if(options.s3.originalname) {
        this.options.generateFilename = function(file, attempt, callback) {
            return callback(null, file.originalname);
        }
    } else {
        this.options.generateFilename = ensureCallback(this.options.generateFilename);
    }

Or should this be handled somewhere higher up in the keystone Types? Or be changed to support a filename function in the Field definition (e.g., filename: (file) => file.originalName)?

mhoffmeyerDC commented 8 years ago

Looking at the forks it seems like @GwonHyeok already found a fix for the issue.

Looks like a better, more robust solution rather than more options.

mhoffmeyerDC commented 7 years ago

CC: @JedWatson

robksawyer commented 7 years ago

For anyone that came here looking for an example of how to use the original file name with this plugin, check out https://gist.github.com/robksawyer/6060412c3f86ddbc68b29ed09eef75c3.

n-devr commented 6 years ago

@robksawyer thank you - that worked a treat 🎉

internetErik commented 5 years ago

Just wanted to note that I was having difficulty in s3 with files that have spaces in them, so when I want to keep the original file name I use this:

generateFilename: file => file.originalname.replace(/ /g, '-'),

I'll also mention this for anyone who wants to generate a public url that is saved. I usually use a method that looks like this:

publicUrl : file => `https:${process.env.S3_BASE_URL}${s3FilePath}${file.filename}`,

The S3_BASE_URL is saved in the .env file. Instead you may have a cloudfront path or whatever else you want.