Allow to customize the key generation used in the companion app #30
Unanswered
RobertAudi
asked this question in
Q&A
Replies: 1 comment 1 reply
-
You should be able to override the default multipart upload key as follows: Shrine.plugin :uppy_s3_multipart, options: {
create_multipart_upload: -> (request) do
filename = request.params["filename"]
file_extension = File.extname(filename)
filepath = filename.gsub(/#{Regexp.escape(file_extension)}\z/, "")
key = [request.params["prefix"], "#{filepath}__#{SecureRandom.hex}#{file_extension}"].compact_blank.join("/")
{ key: key }
end
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Right now the generated key only preserves the original file extension, it replaces everything before by a random string:
uppy-s3_multipart/lib/uppy/s3_multipart/app.rb
Lines 42 to 45 in 404c511
It is possible to specify multiple prefixes but it can only be done once when the app is mounted and can't be changed at runtime.
One use case is to be able to upload files in "a directory tree" defined by Uppy.
For example:
What I had to do is port the Roda app to a Rails controller just to modify the key generation like so:
Beta Was this translation helpful? Give feedback.
All reactions