Restrict file type whendirect upload


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?

When doing this in an HTML form, the content type can be restricted in the policy document by using the “starts-with” condition.

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.