2018-03-25 16:15:39 +00:00
|
|
|
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
|
2018-03-25 17:30:42 +00:00
|
|
|
class AwsPresignedPostsController < ApplicationController
|
2019-07-13 07:53:59 +00:00
|
|
|
before_action :authenticate_user!
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
# post /presigned_posts
|
|
|
|
# Create some keys using the AWS gem so the user can do direct-to-S3 uploads
|
|
|
|
# http://docs.aws.amazon.com/AWSRubySDK/latest/AWS/S3/PresignedPost.html
|
|
|
|
def create
|
|
|
|
uuid = SecureRandom.uuid
|
|
|
|
p = S3Bucket.presigned_post({
|
|
|
|
key: "tmp/#{uuid}/${filename}",
|
|
|
|
success_action_status: 201,
|
|
|
|
acl: 'public-read',
|
|
|
|
expiration: 30.days.from_now
|
|
|
|
})
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
s3_presigned_post: p.fields.to_json,
|
|
|
|
s3_direct_url: p.url,
|
|
|
|
s3_uuid: uuid
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|