Carrierwave Direct and additional form elements

217 views
Skip to first unread message

Walter Lee Davis

unread,
Aug 29, 2012, 3:28:57 PM8/29/12
to rubyonra...@googlegroups.com
I just switched a project from Dragonfly to Carrierwave, specifically to see if I could take advantage of Carrierwave Direct, which uploads large files directly to S3 or another cloud storage.

I was able to make a form containing a single file field that would upload to S3. What I could not work out was how to upload the file to S3 AND other form elements to the model that had Carrierwave mounted on it. I ended up punting and just doing the two-step upload to the server and server stores the file in S3 using regular Carrierwave (not Direct).

Can anyone point me to an example of Carrierwave Direct that incorporates other form fields saved into the same ActiveRecord as the Carrierwave details?

Thanks,

Walter

tundrax

unread,
Aug 30, 2012, 5:24:09 AM8/30/12
to rubyonra...@googlegroups.com
Docs say you should use Fog gem


And it doesn't matter what storage you chose, local filesystem, S3 or any other cloud storage.
Your form is submitted and the location of uploaded file, along with other attributes of the model you are editing
are stored in the database. So, you question

>> What I could not work out was how to upload the file to S3 AND other form elements to the model that had Carrierwave mounted on it.

is inappropriate.

Walter Lee Davis

unread,
Aug 30, 2012, 11:38:35 AM8/30/12
to rubyonra...@googlegroups.com

On Aug 30, 2012, at 5:24 AM, tundrax wrote:
>>
>>
>>
>> On Thursday, August 30, 2012 4:29:25 AM UTC+9, Walter Lee Davis wrote:
>> I just switched a project from Dragonfly to Carrierwave, specifically to see if I could take advantage of Carrierwave Direct, which uploads large files directly to S3 or another cloud storage.
>>
>> I was able to make a form containing a single file field that would upload to S3. What I could not work out was how to upload the file to S3 AND other form elements to the model that had Carrierwave mounted on it. I ended up punting and just doing the two-step upload to the server and server stores the file in S3 using regular Carrierwave (not Direct).
>>
>> Can anyone point me to an example of Carrierwave Direct that incorporates other form fields saved into the same ActiveRecord as the Carrierwave details?
>>
>> Thanks,
>>
>> Walter
>
> Docs say you should use Fog gem
>
> https://github.com/jnicklas/carrierwave#using-amazon-s3
>
> And it doesn't matter what storage you chose, local filesystem, S3 or any other cloud storage.
> Your form is submitted and the location of uploaded file, along with other attributes of the model you are editing
> are stored in the database. So, you question
>
> >> What I could not work out was how to upload the file to S3 AND other form elements to the model that had Carrierwave mounted on it.
>
> is inappropriate.

Sorry, what?

I was able to make a form containing a single file field which would upload using Carrierwave _Direct_ to upload to S3 without my server acting as a middle-man. I was not able to suss out how to combine such a file field with other fields intended for my server's eyes.

I was perfectly able to create a single combined form which contained the file AND its metadata, upload both to my server, and yes, using Fog, store the file on S3. That's with ordinary Carrierwave, which is lovingly documented and a drop-in replacement for nearly every other file storage scheme on Rails.

The issue, which I still do not understand how to solve without an Ajax sidecar submitting two forms at once, is how to send part of the data directly to S3 and the remainder to my server, and maintain a connection between the two.

If you can help, I would appreciate it.

Walter

Mark J. Lehman

unread,
Jul 16, 2014, 12:44:19 AM7/16/14
to rubyonra...@googlegroups.com
Walter,

I know this is almost 2 years old now, but I'm trying to figure out how to do the same thing with Carrierwave Direct. Did you ever solve this? If you did, would you mind posting how? Code snippets are also appreciated.

Walter Lee Davis

unread,
Jul 16, 2014, 9:03:17 AM7/16/14
to rubyonra...@googlegroups.com
No, I never did work this out, had to move on and the solution in place (in production) is sub-standard as a result.

Walter
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/a547b6a1-f15b-450e-a1c1-49fc863cee04%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Walter Lee Davis

unread,
Jul 16, 2014, 9:58:34 AM7/16/14
to rubyonra...@googlegroups.com
Oddly enough, this link just appeared in the Heroku newsletter e-mail: https://devcenter.heroku.com/articles/direct-to-s3-image-uploads-in-rails?utm_source=pardot&utm_medium=newsletter&utm_campaign=july While it uses Paperclip, the technical theory might be applicable to your (our) situation. More study needed...

Walter
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/EC480BF8-F591-46E1-9969-1B7CD2473569%40wdstudio.com.

Mark J. Lehman

unread,
Jul 16, 2014, 3:40:08 PM7/16/14
to rubyonra...@googlegroups.com
Hm, yeah, that could work, though it doesn't seem to use Paperclip or Carrierwave, just straight jQuery File Upload. More complex than I had planned, but I'll give it shot.

Thanks for the resource.

Mark J. Lehman

unread,
Jul 17, 2014, 12:24:35 PM7/17/14
to rubyonra...@googlegroups.com
Thanks again for the link, Walter. With some tweaking, got it working all in the same form. I'm not processing the uploads at all but it seems like you could still use carrierwave or paperclip to process in the background after uploading.
Reply all
Reply to author
Forward
0 new messages