1

I want to upload images to s3. For that I am following http://railscasts.com/episodes/383-uploading-to-amazon-s3

I am able to upload single image to s3 but now I am using jquery file upload to upload multiple files.

It gave me 403(Forbidden) when I tried to upload file.

What do I need to do to fix it?

Thank you to anyone that can help in advance!

Sahil
  • 491
  • 2
  • 9
  • 18
  • https://github.com/pjambet/direct-upload -> from this link you can direct-upload in s3 it's small project you can take clone – Dipak Panchal Nov 27 '12 at 06:20

3 Answers3

0

You need to check the permission of your S3 bucket. It should allow "Upload/Delete".

In addition, you should set up CORS configuration (CORS: Cross-Origin Resource Sharing) (for your bucket, go to Properties ==> Permissions, then click on 'Add CORS Configuration')

The file should have something like this:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>http://localhost:3000</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>

Here it allows my localhost to post files to this bucket.

Zack Xu
  • 11,505
  • 9
  • 70
  • 78
0

While you are testing you can use a very broad CORS config

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Layke
  • 51,422
  • 11
  • 85
  • 111
0

Beside CORS, 403 can come because wrong contentType is set.

Server side:

GeneratePresignedUrlRequest rq = new GeneratePresignedUrlRequest(bucketName, objectKey);
rq.setContentType("video/*");
...

Client side:

$.ajax({
                url:upUrl,
                type: "PUT",
                data: file,
                contentType:'video/*',
                cache: false,
                processData:false,
                success: function (data) {

                }
              });
sigi
  • 189
  • 3
  • 9