问题
I have a web service in Rails which among all else should provide file upload functionality to the clients. The clients all use JSON to talk to the webservice. I use the Paperclip plugin for upload management.
The problem is I do not know how to upload a file via JSON. All works in the web formular, but I cannot find information on how to consctruct my JSON Request to send files to the server. Can somebody help out?
Regards, Angel Kafazov
回答1:
You don't need to use Paperclip for uploading JSON files in rails. Use the following syntax inserting the file upload field to your view. To read the JSON files in your controllers, import JSON package to read the contents.
<%= file_field 'LABEL', 'QUERY_PARAMETER_NAME' %></p>
回答2:
I didn't try this yet, but this looks promising:
http://leejava.wordpress.com/2009/07/30/upload-file-from-rest-in-ruy-on-rail-with-json-format/
来源:https://stackoverflow.com/questions/2763787/how-to-upload-file-via-the-json-interface-in-rails