Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Upload within a model form #5

Closed
rapcal opened this Issue Oct 24, 2011 · 9 comments

Comments

Projects
None yet
6 participants

rapcal commented Oct 24, 2011

I'm not sure if this is the place for questions, so please delete it if innapropriate. I just couldn't find a forum or another place that seemed better suited.

I'm uploading a user avatar with carrierwave, which works inside a regular form_for. So I get the avatar along with all the rest of the user info.

However, with carrierwave_direct, something like this would not work, since I would need to nest the direct_upload_form_for inside a form_for. Something like this:

<%= form_for @user, :html => { :multipart => true } do |f| %>
  <%= f.error_messages %>
  <%= f.label "What's your name?" %>
  <%= f.text_field :name %>
  <%= f.label "What's your birthday?" %>
  <%= f.date_select :birthday %>
  <%= direct_upload_form_for @uploader do %>
    <%= f.label "Upload your avatar" %>
    <%= f.file_field :avatar %>
    <%= f.submit %>
  <% end %>
  <%= f.submit =>
<% end %>

Anyway to get around this? I would really love to avoid a flash uploader.

Thanks for the great gem! Hope I'm able to get it working on my scenario.

Owner

dwilkie commented Oct 26, 2011

Hey,

Remember that when you use: <%= direct_upload_form_for @uploader %>
The form will post directly to S3. If the upload is successful S3 redirects the user back to your application but it only includes the bucket, key and etag and nothing more.

When I want to use this gem with a project such as yours, I would use a multi-stage form, so that the user can upload their avatar first in a form on it's own by selecting a file then pressing "Next", then you have the form to create their profile on the next page.

There's an example of this in the README under: Processing and referencing files in a background process

For more info on what S3 returns see: http://doc.s3.amazonaws.com/proposals/post.html

@dwilkie dwilkie closed this Oct 26, 2011

rapcal commented Oct 26, 2011

Thank you a lot for your feedback!

I'm grappling with a similar question, but more so from a reverse perspective (retrieving the uploaded file from a S3 bucket). I have the following test app that successfully uploads with carrierwave_direct and then goes on to call the new method of an associated model:

https://github.com/ryanmcadler/carrierwave_direct_test_app

How should call the uploaded file in say, the show view of an associated model? I assume the usual means of doing this with just carrierwave/fog (e.g. post.photo_url() ) won't work because the file gets stored within a UUID-named directory?

Thanks in advance...

npflood commented Feb 27, 2012

I hunted quite a while looking for this same answer, I recommend bumping this information into the README. This is especially important because currently the documentation makes CarrierWave_Direct look like it operates in precisely the same way as CarrierWave, which it doesn't, and for good reason.

@dwilkie dwilkie reopened this Feb 28, 2012

Owner

dwilkie commented Feb 28, 2012

@npflood feel free to add what you think is missing to the README and send me a pull request and I'll pull your changes in.

@dwilkie @npflood It would be my pleasure to submit a pull request for the README but I haven't had time lately to work out my issue.

@npflood Could you perhaps post the resource that helped you figure it out?

Alternatively, if a simple demo app could be committed this would really help.

+1 for a demo app

Tarikus commented Jun 25, 2012

+2

@dwilkie dwilkie closed this Oct 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment