Thanks for posting the conclusion!

Posting the resolution only takes a few minutes, but its so helpful for
future readers, and those of us just keeping tabs on the thread.

Thanks

On Fri, May 6, 2011 at 8:31 AM, batate <br...@rapidred.com> wrote:

> Here's the solution for posterity. There were two problems to solve:
>
> Recall that I'm using CarrierWave.
> 1) Heroku allows permissions only to the tmp directory. I needed to
> specify the cache dir on the attachment uploader.
> 2) I needed to set content headers for s3. You can specify them when
> you upload a file, and Amazon will provide them in the content headers
> when you download a file.
>
> So in my model (Mongoid), I have
>
> class Report
>  include Mongoid::Document
>
> ...
>
>  mount_uploader :attachment, AttachmentUploader
>
>
>
>
>
> And in my uploader, I have:
>
> class AttachmentUploader < CarrierWave::Uploader::Base
>
>
>  def store_dir
>    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
>  end
>
>  def s3_headers
>   { "Content-Disposition" => "attachment; filename=export.csv;" }
>  end
>
>  # Use Heroku's temp folder for uploads
>  def cache_dir
>     "#{Rails.root}/tmp/uploads"
>  end
>
> end
>
>
>
> The s3 headers above set the content disposition type to attachment,
> so it will download as a file instead of a page. The filename will set
> the filename upon download.
>
> The cache_dir sets the temp holding area for Heroku, since the
> uploads/ directory is not public.
>
>
> To upload an attachment, I say report.attach. That does this:
>
>  def attach(filename)
>    self.attachment = File.open(filename)
>    self.save
>  end
>
>
>
> Hope this helps.
>
> -bt
>
> On May 5, 10:51 am, batate <br...@rapidred.com> wrote:
> > I am uploading reports, via Carrierwave, to Amazon s3, but with
> > protected urls. I'm able to process the upload fine, and I can see the
> > file on Amazon, but it renders as text. I want it to trigger a browser
> > download instead of just render the text.
> >
> > When I was generating the file via a template, I could control the
> > headers and force the right download like this:
> >
> >  helper_method :render_csv
> >   def render_csv(file, view=nil)
> >     filename = "export"
> >     filename = "user_export" if params[:action] == "process_users"
> >     filename ||= params[:action]
> >     filename += '.csv'
> >
> >     (request.env['HTTP_USER_AGENT'] =~ /msie/i) ?
> > set_ie_headers( filename ) : set_headers( filename )
> >     render :layout => false, :action => view
> >   end
> >
> > But now, I'm downloading from s3.
> >
> > Any suggestions?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Heroku" group.
> To post to this group, send email to heroku@googlegroups.com.
> To unsubscribe from this group, send email to
> heroku+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/heroku?hl=en.
>
>


-- 
-John

-- 
You received this message because you are subscribed to the Google Groups 
"Heroku" group.
To post to this group, send email to heroku@googlegroups.com.
To unsubscribe from this group, send email to 
heroku+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/heroku?hl=en.

Reply via email to