DART message with multipart / form data
in DART lang how to specify POST Content-Type request for
multipart/form-data
My DART code:
sendDatas(dynamic data) { final req = new HttpRequest(); req.onReadyStateChange.listen((Event e) { if (req.readyState == HttpRequest.DONE && (req.status == 200 || req.status == 0)) { window.alert("upload complete"); } }); req.open("POST", "/upload"); req.send(data);
}
I am doing a POST with a file
source to share
I think you should be using HttpRequest.postFormData(url, data)
here. Then you can use the following:
FormData data = new FormData(); // from dart:html data.append(key, value); HttpRequest.request('/upload', method: 'POST', sendData: data).then((HttpRequest r) { // ... });
Regards, Robert
source to share
The http
package is supported on the server . This package can also be used in the browser, but it seems the file multipart_request.dart
cannot be imported in the browser because it uses dart:io
;
I suggest creating a feature request at http://dartbug.com/new .
You can also try to copy the code from the [http] package and remove the package references io
and use the browser API.
How this can be used on the server is shown here http://www.dartdocs.org/documentation/http/0.11.1+1/index.html#http/http.MultipartRequest
source to share