如何使用Dart从浏览器发送多部分HTTP请求 [英] How to send multipart HTTP requests from browser with Dart
问题描述
我必须将图片从浏览器上传到我使用Python Eve实现的RESTful网络API。从文档,它需要发送multipart / data-form请求。 ( http://python-eve.org/features.html#file-storage)。有'dart:http'库可以做。但是,它需要dart:io,这不是在浏览器上可用。
I have to upload an image from browser to my RESTful web API, implemented using Python Eve. From documentation, It requires sending multipart/data-form request. (http://python-eve.org/features.html#file-storage). There is 'dart:http' library that could do. But, it requires 'dart:io', which is not available on browser. So, is there anyway I can send the request from browser?
感谢您的帮助。
推荐答案
您可以使用这样的:
FormData formData = new FormData();
formData.append('image', '...');
HttpRequest.request('url', method: 'post', sendData: formData).then((HttpRequest request) {
// ...
});
这应该设置正确的mimeType。如果没有,您可以使用mimeType参数设置它。
This should set the correct mimeType. If not you can set it with the mimeType parameter.
尊敬的,
Robert
Regards, Robert
这篇关于如何使用Dart从浏览器发送多部分HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!