如何在Dart中动态添加文件输入到FormData? [英] How do I dynamically add a file input to FormData in Dart?

查看:574
本文介绍了如何在Dart中动态添加文件输入到FormData?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用FormData类通过HttpRequest.send()将数据发送到我的服务器。我需要做一个POST请求与多个字段。它应该与此Javascript代码一样工作:

I am trying to use the FormData class to send data to my server with HttpRequest.send(). I need to do a POST request with multiple fields. It should work the same as this Javascript code:

//Upload File
var uploadFile = function(file, tag, callback)
{
    var xhr = new XMLHttpRequest();
    xhr.open('POST', "upload/", true);
    xhr.onreadystatechange=function()
    {
        if (xhr.readyState==4 && xhr.status==200)
        {
            callback();
        }
    }
    var formData = new FormData();
    formData.append('file', file);
    formData.append('tag', tag);
    var csrftoken = $.cookie('csrftoken');
    xhr.setRequestHeader("X-CSRFToken", csrftoken);
    xhr.send(formData);
};

但是FormData似乎在Dart中没有同样的效果。

But FormData doesn't seem to work the same way in Dart. Could someone explain how to do this in Dart, if it is possible?

推荐答案

不幸的是,这看起来像是一个错误。我打开了 http://code.google.com/p/ dart / issues / detail?id = 7152 来跟踪。感谢您的使用案例。

Unfortunately this looks to be a bug. I've opened issue http://code.google.com/p/dart/issues/detail?id=7152 to track. Thanks for the use case.

这篇关于如何在Dart中动态添加文件输入到FormData?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆