2

我在测试中使用这样的东西:

_sendFormData(final File file) {
    final HttpRequest httprequest = new HttpRequest();
    final String filename = file.name;

    httprequest.open('POST', "http://localhost:8080/api/file/upload");
    httprequest.on.readyStateChange.add((e) {
      if (httprequest.readyState == 4 && httprequest.status == 200) {
        window.alert("upload complete");
      }
    });

    print("Filename: ${filename}");

    final FormData formData = new FormData();
    formData.append('file', null, filename);
    httprequest.send(formData);
}

是的,我知道这只是我要发送的文件名,但是如何将整个文件发送到服务器?

4

2 回答 2

6

您应该能够上传file

formData.append('file', file);
于 2012-12-26T21:15:04.430 回答
4

他们引入了一个新函数来附加具有给定文件名的文件:

FormData.appendBlob(String name, Blob value, [String filename]) 
于 2015-06-03T09:52:01.337 回答