How to upload file via the JSON interface in Rails

本小妞迷上赌 提交于 2019-12-22 08:17:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!