Heroku article on creating a direct to S3 upload

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!

Hello Christopher,

I trust you are well.

I am not a programmer and need help uploading and hosting a website on
Heroku. The site was developed using Ruby on Rails and in my part of the
world, a good programmer in this field is hard to come by.

Can you help and what are the steps to do so.

Many thanks.

Tony