繁体   English   中英

从HTML5文件系统api上传

[英]Uploading from HTML5 filesystem api

我正在使用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是FileEntry,因此我必须请求文件本身,因此将代码更改为:

// 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);

解决了这个问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM