Skip to main content

12 Direct Uploads with ActiveStorage

Episode 246 · May 31, 2018

Learn how to enable direct uploads in the browser to Amazon S3 or DigitalOcean Spaces using Rails' new ActiveStorage library

ActiveStorage File Uploading


Transcripts

No transcripts available. Earn a free month

Discussion


Gravatar
I'm running to a small error I think.

Alright, so when I try to get the a file to upload It seems to begin the process and then commit but then it stops. I get a completed 200 ok but the issue is that it doesn't actually get the file to upload nor does it create a new post. 

I have restarted my server and tried bundle install. I've also looked through the Github to try and see if I missed anything and so far that is a no. I have also went over the process of s3cmd again to verify if everything is working correctly and it seems as if this checks out also. 

The only difference with our code is that I'm being lazy and using my access key and secret key directly in my storage.yml file and not using <%= ENV["S3_KEY"] %> and <%= ENV["S3_SECRET"] %>.

What do you think my issue could be? Could someone please help me? 

Thank you so much ahead of time :) 

Gravatar
HI, 
I am having an error in production.

In development locally everything is working perfectly but in production I am getting this error:

NoMethodError (undefined method `upload' for nil:NilClass)
Did somebody has a same or similar error?
Gravatar
Verify if the image exists before:

<% if post.photo.attached? %>
   <%= image_tag post.photo %>
<% end %>

Gravatar
When the image is uploaded to DigitalOcean Spaces, the permissions are as private. Does anyone know how to upload the image with public permissions?

Gravatar
Hey Chris, thanks for another great video.

I've been trying to get direct uploads to work on production (it's fine on localhost) but I'm getting a Cross Origin Error when I test live with SSL enabled.
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

Any idea why this might be happneing?

Cheers.


Gravatar
In case anyone bumps into this response, I found out that I had setup my domain name incorrectly on the CORS configuration in Digital Ocean. So you might want to check that config out.

Login or create an account to join the conversation.