multipart/form-data vs application/octet-stream

六眼飞鱼酱① 提交于 2019-12-21 07:00:54

问题


I'm creating a simple REST API for uploading files. From other API's I found they use "multipart/form-data" content type. But for me, it looks like "application/octet-stream" is much simpler.

If I don't intend to send any more form data with the file is there any reason to use "multipart/form-data" and not "application/octet-stream" ?


回答1:


While you don't intend to send any other data together with the file right now, multipart/form-data would give you the possibility to add additional data later on if this is required (without breaking compatability).

Also multipart/form-data would make it possible to access the REST API directly by submitting an HTML form (see https://stackoverflow.com/a/4526286/693140).

Your API could however support both types by using the client's content type header to distinguish between them.



来源:https://stackoverflow.com/questions/29347234/multipart-form-data-vs-application-octet-stream

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