且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

REST API设计将JSON数据和文件发送到同一请求中的api

更新时间:2023-09-07 22:23:04

我认为这是一个非常令人讨厌的问题,正确的方式来做这是一个多部分消息。这样,你可以发布JSON和图像与它们相应的正确的MIME类型。 ***关于多部分MIME类型的文章提供了一个示例。看起来像Apache httpcommons和Jersey都支持这种事情,显然 curl也太!

I think the "right" way to do this is with a multipart message. That way, you can post up both the JSON and the Image with their corresponding correct MIME type. The wikipedia article on multipart mime types has an example of what this would look like. It looks like both Apache httpcommons and Jersey support this sort of thing, and apparently curl does too!