使用 Paperclip 通过 http 将图像发布请求上传到其他应用程序 [英] Upload image post request over http to other application using Paperclip
问题描述
我可以使用回形针将图像附件上传到我的应用程序.但我想通过法拉第连接将图像发送到另一个应用程序.其他属性已成功发送,但不是附件图像.我不确定我应该怎么做才能实现这一目标.
I am able to upload image attachements using paperclip to my application. But I would like to send the image to another application via faraday connection. Other attributes are successfully sent but not the attachment image. I am not sure what I should do to achieve this.
推荐答案
您需要使用可以创建多部分 Post 请求的 HTTP 库.
You need to use an HTTP library that can create Multipart Post requests.
例如 Typhoeus 可以上传文件:https://github.com/typhoeus/typhoeus#handling-file-uploads.
For example Typhoeus can do file uploads: https://github.com/typhoeus/typhoeus#handling-file-uploads.
还有 Net::HTTP Multipart Post:https://github.com/nicksieger/multipart-发帖
There's also Net::HTTP Multipart Post: https://github.com/nicksieger/multipart-post
最后:https://github.com/jwagener/httmultiparty
阅读这些 gem 的自述文件,它们都使上传文件变得同样容易.我喜欢 Typhoeus,因为它可以执行并行请求.另外两个更简单,但同样有用.
Read the READMEs to any of those gems, they all make it equally easy to do file uploads. I like Typhoeus because it can do parallel requests. The other two are a bit simpler but equally useful.
详细了解什么是多部分表单帖子:
Learn more about what a multipart form post is:
- 什么是 http 多部分请求?
- application/x-www-form-urlencoded 或 multipart/form-data?
- http://www.huyng.com/posts/under-the-hood-an-http-request-with-multipartform-data/
这篇关于使用 Paperclip 通过 http 将图像发布请求上传到其他应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!