Ask A Question


You’re not receiving notifications from this thread.

Refile S3, presigned, multiple files + Cloudfront - generating images via javascript

Dean Fields asked in General


I have followed along with both videos, but have come up with a little issue while attempting to generate a thumbnail within the success event. It seems to be automatically requiring the token which is not required in these videos.

I have not set a secret_key within my initialiser as the documentation suggests. I have discovered you can generate and check a token via these commands:

example url: (/store/fill/400/200/a7d1406d633ce73f124a33598690d146f8fd422dbf66d9f56b6a12eb2d31/image)

I paste these in to the js line for displaying the image:

$(fileupload_id + ' img').attr(
src: "/attachments/[token here]/[url here]"

This now works and shows the image. - of course it's not the one being uploaded, but one I took from s3 from a previous upload

is there a way to generate the token via javascript?


I believe the secret_key is a new security feature added recently and you probably just need to follow it's instructions.

This wasn't something that existed when I recorded those videos originally.


Thanks Chris,

I will take a second glance, but I don't think it's explained in the instructions


It looks like when the error gets thrown, they give you a random secret key that you should copy paste into an initializer then restart your app and you should be good.


Ah right!, ok thank you very much


Let me know if that works for you. I'll have to update the video soon.

That's always the hard part of making screencasts for gems like this!


Ok so in my view I outputted refile.secret_key and it seems to be set somehow.

I copied and pasted this in to the initializer just to see if it would make a difference. When I took the token out of the url, no luck. I'm not receiving any errors in my logs or anything when I don't set secret_key so it must being set by the system itself?

I made sure I restarted.

Using <%= attachment_image_tag(photo, :image, :fill, 300, 300) %>

Seems to set the token in the url - but I haven't got a secret_key set?

But no errors seem to be occurring?

I can only imagine, it's almost like you need to make micro videos for each thing so that it can be modularly updated when things change :)


It might be. I didn't see anything requiring you to set it. I just updated the code from the GoRails episode and everything is working fine without the token(and it didn't require me to put the token in the URL).

You're doing this with S3 presigned uploads and that seems to be the piece that's requiring the token?


<%= f.attachment_field :photos_images, multiple: true, direct: true, presigned: true, host: '' %>

This is my attachment field currently. I'm going to attempt to try a couple of things out, i.e removing presigned and attempt to see if I can figure out where the issue is, by looking at the differences between mine and yours.

I've also set my to use Cloudfront. I had to set host: '' on the attachment field otherwise the URL when uploading gets messed up:

[cf url] 404 (Not Found)

If I remove // on the front of

the images for attachment_image_tag work, but do not if // is added (have to overwrite the host again)

I'm not sure what is factoring this or if it's connected

Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 84,256+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.