简体   繁体   English

通过REST API上的GET请求发送图像数据

[英]Sending Image data through GET request on REST API

I have a REST API at the backend (built on flask). 我在后端有一个REST API(基于烧瓶)。 Now i need to send/upload an image at the client side and return JSON in response. 现在我需要在客户端发送/上传图像并返回JSON作为响应。 So that would be GET request with Image data. 这就是带有图像数据的GET请求。 Since i'm new to the client side interface, what could be the simplest way to send an image data to the server? 由于我是客户端界面的新手,将图像数据发送到服务器的最简单方法是什么? There just needs to be an upload image button to get the JSON in response. 只需要一个上传图像按钮即可获得JSON作为响应。 I've read answers to base64 encode the image file and send it with no simple example on how it should be done. 我已经阅读了base64编码图像文件的答案,并没有简单的示例说明如何发送它。 Many have suggested Knockout or Angular but i don't have much time to go through them. 许多人建议使用Knockout或Angular,但我没有太多时间来研究它们。 Please suggest if there's a simpler way as well. 请提出是否还有更简单的方法。

In REST, GET should return values, not change data on the server. 在REST中,GET应返回值,而不是更改服务器上的数据。 All the request information is sent via the URL, as well, which may produce problems if it's too long . 所有请求信息也都通过URL发送,如果它太长 ,可能会产生问题。

So use PUT or POST and send the data: 所以使用PUT或POST并发送数据:

$.ajax({
  url:'the service url',
  method: 'PUT',
  data: { image: base64ImageString }
});

Additional info from a very similar question [hint!] here: Jquery Ajax - post huge string value 来自一个非常相似的问题的其他信息[提示!]: Jquery Ajax - 发布巨大的字符串值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM