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.
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?
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.
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
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.
-> 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.
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