Hello all,
I followed the Heroku article on creating a Direct to S3 file uploader
for
my Rails app.
I think that I did everything the tutorial said…
In my users_controller, under new is:
@s3_direct_post = S3_BUCKET.presigned_post(key:
“uploads/#{SecureRandom.uuid}/${filename}”, success_action_status: 201,
acl: :public_read)
This code seems fine, and is pretty much exactly as the article says.
The problem is in my image_loader.js.erb, the following:
fileInput.fileupload({
fileInput: fileInput,
url: ‘<%= @s3_direct_post.url %>’,
type: ‘POST’,
autoUpload: true,
formData: <%= @s3_direct_post.fields.to_json.html_safe %>,
Turns out:
undefined method `url’ for nil:NilClass
in fact this breaks an otherwise working app.
The code in my controller should create the @s3_direct_post object,
but
it seems that my javascript doesn’t pick it up, maybe?
I’ve tried putting the code in the view with tags, as well,
with
the same results. Any help out there?
Thanks!