Javascript 从HTML5文件系统api上载

Javascript 从HTML5文件系统api上载,javascript,c#,angularjs,html,Javascript,C#,Angularjs,Html,我正在利用html5文件系统api,并试图将一些图像上传到C#WebApi 但这些总是空的。不管我怎么努力, 我在API中使用以下代码 [HttpPost] [Route("api/quotation/pictures")] public HttpResponseMessage PostImages() { try { _logger.Trace("Post pictures ..."); NameValueCollection parameters =

我正在利用html5文件系统api,并试图将一些图像上传到C#WebApi

但这些总是空的。不管我怎么努力, 我在API中使用以下代码

[HttpPost]
[Route("api/quotation/pictures")]
public HttpResponseMessage PostImages() {
    try {
        _logger.Trace("Post pictures ...");
        NameValueCollection parameters = HttpContext.Current.Request.Params;
        string filename = parameters.GetValues("id")[0];
        var files = HttpContext.Current.Request.Files;
        if (files.Count > 0) {
            // .. other code
        }
    }
}
下面是JS中的代码

// img = variable with some img options.
var data = new FormData();
fileService.getFile(img.viewpath.split('/').pop()).then(function (f) {
    // f = FileEntry
    data.append(img.FileNameOnDevice, f);
    $.ajax({
        url: url,
        type: "POST",
        data: data,
        contentType: false,
        processData: false
    }).success(defImg.resolve).error(defImg.reject);
}, function () {
    console.error("not found");
});
这是一个简单的解决办法

由于
f
是一个文件条目,我必须请求文件本身,因此将代码更改为:

// img = variable with some img options.
var data = new FormData();
fileService.getFile(img.viewpath.split('/').pop()).then(function (f) {
    // f = FileEntry
    f.file(function(file){
        data.append(img.FileNameOnDevice, file);
        $.ajax({
            url: url,
            type: "POST",
            data: data,
            contentType: false,
            processData: false
        }).success(defImg.resolve).error(defImg.reject);
    }, defImg.reject);
}, defImg.reject);

已解决问题

您是否正在尝试使用JavaScript访问用户的文件系统?因为你不能(在浏览器中)。我可以使用文件系统来显示存储在文件系统中的文件(我把它们写在那里)