Skip to content
This repository has been archived by the owner on Nov 24, 2021. It is now read-only.

No option to use original filename #11

Open
mhoffmeyerDC opened this issue Oct 30, 2016 · 5 comments · May be fixed by #12
Open

No option to use original filename #11

mhoffmeyerDC opened this issue Oct 30, 2016 · 5 comments · May be fixed by #12

Comments

@mhoffmeyerDC
Copy link

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
Copy link
Author

mhoffmeyerDC commented Oct 30, 2016

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 mhoffmeyerDC linked a pull request Oct 30, 2016 that will close this issue
@mhoffmeyerDC
Copy link
Author

CC: @JedWatson

@robksawyer
Copy link

robksawyer commented Apr 14, 2017

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
Copy link
Contributor

n-devr commented Oct 2, 2018

@robksawyer thank you - that worked a treat 🎉

@internetErik
Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants