Not able to upload file #1

Open
sahil2628 opened this Issue Nov 30, 2012 · 2 comments

3 participants

@sahil2628

Excellent episode.I am able to upload single file with carrierwave.

But I got 403(Forbidden) error when I try to upload multiple files using jquery file upload.

When I try to upload single/multiple file I get alert box saying failed to upload and in console it says "Failed to load resource: the server responded with a status of 403 (Forbidden)" and "XMLHttpRequest cannot load https://xyz.s3.amazonaws.com/. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin."

What do I need to do to fix this?

Thank you

@joshk6

While this demos a destroy action, from what I can tell the file once uploaded in S3 will stay there, just no longer accessible through the rails app. Seems like it would be nice if this demo showed how to delete form s3 as well, not just to add.

@marks

Indeed.. I ended up implementing this myself in the model using the following code:

before_destroy :delete_from_s3

def connect_to_s3
    s3config = UploadHelper::S3Uploader.new({})
    AWS::S3::Base.establish_connection!(
        :access_key_id => s3config.options[:aws_access_key_id],
        :secret_access_key => s3config.options[:aws_secret_access_key]
    )
    AWS::S3::S3Object.set_current_bucket_to(s3config.options[:bucket])
end

def delete_from_s3
    connect_to_s3
    AWS::S3::S3Object.delete(decoded_path)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment