Rails newbie in dire need of help - File uploading

Hey there,

I'm new to Ruby on Rails. REALLY new. So far, I've managed to create an app, a controller, a route and I've managed to push this plain-text application to Heroku and deploy it there.

The app is supposed to be a image uploading website, but instead of just storing the files on the file system, it should cURL the data to an image hoster's API and return the image links.

The main problems I'm facing are..

- I have never worked with MVC before - I'm pretty good with PHP but I completely suck at RoR - Storing files on Heroku's file system is not allowed

But how am I supposed to send files via cURL if I'm not allowed to store them on the file system?

I'd be really grateful for any newbie-friendly advice on this.


Look at the paperclip plugin; it can store uploaded files on Amazon S3, for instance, so even if you're using some other storage it should give you some ideas.

And FWIW I've used it for exactly your use case of deploying an app with an image (photo) upload to Heroku.

Hey Hassan,

thanks for your reply. Paperclip looks interesting, but as of what Google says, it does not support cURL. I've already built a PHP image uploading API, and I want to use it with Rails. Is there any way to accomplish that or do I have to use PHP?


I'm not sure what you're asking -- you want to use PHP in a Rails app that runs on Heroku?

No, i've already built a PHP script which can be used to upload images via HTTP POST. Now I'm trying to build some sort of graphical interface with Rails. Thus, this GUI app would need to use cURL to transfer the uploaded images to the API script.

Sorry, I'm not following you at all.

You have a Rails app on Heroku, and you want to store images for that app somewhere. So why not just use Paperclip? What's the point of a separate upload mechanism?

He has a PHP script that do "the thing" with amazon, but now he needs to tailor the Rails front-end app with that script through cURL. Right Moritz?

You can execute cURL through Rails controllers like:

class SomeController < ...   def execute_my_php_script     `curl http://myscript.moritz.com [options]` # you need to know how to run curl properly here   end end

- I have never worked with MVC before - I'm pretty good with PHP but I completely suck at RoR

Cheers! Jakub Godawa

Yes exactly Jakub! The main problem is that Heroku (The hoster) does not allow any storing of files on their filesystem. Is there any other way?

Sorry, I still don't get it. Why not just use Paperclip and forget about trying to kludge together something with PHP?

Hey there,

okay once again :slight_smile:

I have already coded an image uploading API using PHP. This API can be accessed and used to upload images via cURL. For anyone interested, said API is public and fully working.

Example: curl -F "@picture.jpg" imagecloud.us - This website is for sale! - imagecloud Resources and Information.

-> Will return a JSON-encoded response including image URL etc.

To learn Rails, I want to create a graphical interface for this API. The problem is, the hoster I want to host this Rails GUI on does not allow the storing of files on the filesystem. Thus, putting the files in a temp directory on the filesystem and then transferring them is NOT an option.

Sorry if my posts are a bit complicated, I'm from Germany and not really used to the english language.


Could you use a form in your upload page that sets up a direct post to your imagecloud server, and sends along a unique identifier with that file? Then your imagecloud could post-back with the create file's metadata, and your Rails app could listen for that and update the record asynchronously.


Ah that'd actually work, yeah! :slight_smile:

How would I set up such a form with Rails?

Just found something on Ruby on Rails Guides:


Especially this code part:

def upload   uploaded_io = params[:person][:picture]   File.open(Rails.root.join('public', 'uploads', uploaded_io.original_filename), 'w') do |file|     file.write(uploaded_io.read)   end end

Wouldn't you be able to, instead of file.write, transfer the files via cURL?

Yes, I think that's what one of the other people on this list was saying in this thread. Ruby has cURL support baked in, and you can invoke it directly within your Rails app as long as you know the correct command format.


There are View Helper functions for building a generic form -- one not bound to a particular model instance. Have a look at the form_tag helper in the documentation. That can build any sort of form tag, pointed anywhere. Within it, you would put your unique identifier. You're showing this form to an authenticated user, so you could do something where you stash that user's id concatenated the current time in milliseconds or something like that. Persist that in your database, in the same table where you will eventually have all the details about your cloudy file. Then express that key as a hidden form element in your upload form.


instead of passing picture.jpg to imagecloud couldnt you pass [:person][:photo] to imagecloud? You shouldnt need to write anything, simply pass the raw data to imagecloud