Restrict file type whendirect upload

dreamobjects

#1

Hi,

is there any way to restrict the file’s type to only “png” or “jpg” ?

I am using this with ruby aws-sdk v1 but content_type option doesn’t seem to do anything!

@s3_direct_post = S3_BUCKET.presigned_post( key: "uploads/#{SecureRandom.uuid}/${filename}", success_action_status: '201', acl: 'public-read', content_type: 'image/png' )

any idea?


#2

When doing this in an HTML form, the content type can be restricted in the policy document by using the “starts-with” condition. http://docs.aws.amazon.com/AmazonS3/latest/dev/HTTPPOSTForms.html#PolicyConditions

When you’re creating a pre-signed post, you’re only specifying the content type that is set on upload - the functionality there isn’t to restrict the types. If possible, you could try doing a check on the mime type using some ruby before uploading.