On the web side of things, I have two fields: name, and document. Document is a file field, and name is just what the user wants to call the file in the app.
Here is what I have tried:
curl -F "media[document]=@a.png" -F "media[name]=api" "http://example.com/medias/create.xml?api_key=123"
but I get an InvalidAuthenticityToken Error.
This error only occurs when I try to upload a file / make a media object. The other API / xml commands work (the ones not involving files)
what is the correct way to upload a file using cURL?
EDIT:
adding -H “Content-Type: application/xml” to the above curl command make the server generate this error:
/!\ FAILSAFE /!\ Tue Jan 24 08:45:03 -0500 2012
Status: 500 Internal Server Error
#<REXML::ParseException: malformed XML: missing tag start
Line:
Position:
Last 80 unconsumed characters:
<:??OH?ɽ?H? ???g??yx~t????op?.$?????P&W ??"?
normally the XML is supplied using the -d argument. but I don’t think files can be included in xml? maybe they can? idk.
If you want to create file from xml, you should format your xml to use data, either Base64 and/or CDATA, depending of your needs. Once you have a corretly formatted xml file, you just have to send it with curl.
If you just want to upload file, you don’t need to use an xml interface. You can just call :
For your authentification problem, if you still have it on this url (I do not encounter it on a new rails 3.2.1 fresh app), you can access it with a regular browser, get the cookie information and send it with curl. It means that you will add to your command :
Or use a convenient script to send all your current Firefox cookies from an host into curl.