baash05
baash05

Reputation: 4516

Rails: How to process a file that was sent with curl

I'm trying to create a restful api capable of receiving a file. http://leejava.wordpress.com/2009/07/30/upload-file-from-rest-in-ruy-on-rail-with-json-format/ talks of how to accomplish this simply.

Not being very used to rails or curl, I don't know how to formulate my curl call. Could anyone help me. Explain how to use curl to send a file, and how to use rails to accept and store the file. Note.. the file is a 10 meg zip file. For testing I called it. C:\test.zip..

I've looked at tutorials, but they all seem to be web page based. They also all degrade to resizing pictures.. Like uploading and presenting images are the same topic.

Upvotes: 1

Views: 1799

Answers (1)

Paul Jowett
Paul Jowett

Reputation: 6581

You need to know a bit about how your server-side is expecting the data. If it is a http POST with multipart/form-data (which I think it is), then this will probably help:

curl  -F "fileParam=@c:\test.zip" -F "param1=xxx" -F "param2=yyyy" http://my.server/post-service

This will use curl to post form-data (including a file) to the given url with the given parameters. You need to know the parameter names for the file and the other optional parameters, and you have to obviously get the URL correct to reach your service.

Hope that helps.

Upvotes: 5

Related Questions