Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to upload file #1

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

Not able to upload file #1

sahil2628 opened this issue Nov 30, 2012 · 2 comments

Comments

@sahil2628
Copy link

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
Copy link

joshk6 commented Nov 30, 2012

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
Copy link

marks commented Aug 9, 2013

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants