zend - 使用 REST 服务上传文件
我使用 zend 框架并使用一些 Web 服务(插入、更新、删除,但使用 int、字符串参数)。现在我不知道如何使用 zend 和 Web 服务(REST)上传文件(例如图像)。有人有例子吗?
i use zend framework and work with some web services(insert, update, delete but with int, string parameters). Now i don't how to upload file(for example image) with zend and web services(REST). Does anyone have some example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该通过邮寄电话发送文件。当您执行其他功能时,Rest 服务将收到 postAction。但是,对于文件,您无法使用 ajax 进行调用,因此您需要在客户端执行一些小技巧。
请记住,REST 服务将实施后期操作并接收您通常收到的参数。如果您知道如何使用标准 php 接收和操作文件,则可以在 REST 服务实现中完成。
客户端的技巧是创建一个不可见的 iFrame 并将提交表单目标重定向到它。
此链接通过代码示例很好地解释了此方法:
form POST in iframe而不影响历史记录
http://ajaxpatterns.org/IFrame_Call
http://geekswithblogs.net/拉希德/archive/2007/08/01/Create-An-Ajax-Style-File-Upload.aspx
http://www.openjs.com/articles/ajax/ajax_file_upload/
http://viralpatel.net/blogs/2008/11/ajax-style-file-uploading-using-hidden-iframe.html
合十礼!!
You should send the file throught post call. The Rest service will receive the postAction as when you do what ever other functions. But, with files you cannot make the calls with ajax, so you have a little trick to do in client side.
Remember, REST service will implement post action and receive the parameters as you would receive normally. If you know how to receive and manipulate a file with standard php, you can do it in REST service implementation.
The trick on client side is to create an invisible iFrame and redirect the submit form target to it.
This links explain this method very well with code samples:
form POST in iframe without affecting history
http://ajaxpatterns.org/IFrame_Call
http://geekswithblogs.net/rashid/archive/2007/08/01/Create-An-Ajax-Style-File-Upload.aspx
http://www.openjs.com/articles/ajax/ajax_file_upload/
http://viralpatel.net/blogs/2008/11/ajax-style-file-uploading-using-hidden-iframe.html
Namastê !!