Dropzone 无法识别文件或 MIME 类型请求标头。MVC .NET

clD*_*clD 6 javascript c# jquery xmlhttprequest dropzone.js

我正在使用Dropzone.js上传带有.msg扩展名和 MIME 类型的文件application/vnd.ms-outlook。

当我选择带有.msg扩展名的文件时,文件类型为空。

这可以通过实现一个accept函数并设置文件类型来解决,但是,当发送请求时,MIME 类型设置为application/octet-stream当内容类型未知或为空时的默认值。


题

如何在to 中设置Content-Type文件,例如MyFile.msg?multipart/form-data;application/vnd.ms-outlook


要求

POST www.someurl.com
...
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryMagrF5N9EvrTWyiY
Accept: application/json
X-Requested-With: XMLHttpRequest
...

------WebKitFormBoundaryMagrF5N9EvrTAAA
Content-Disposition: form-data; name="Filename"

MyFile.msg
------WebKitFormBoundaryMagrF5N9EvrTAAA
Content-Disposition: form-data; name="Details"

------WebKitFormBoundaryMagrF5N9EvrTAAA
Content-Disposition: form-data; name="file"; filename="MyFile.msg"
Content-Type: application/octet-stream //NEED TO CHANGE
Run Code Online (Sandbox Code Playgroud)

拖放区

accept: function (file, done) {

        // file.type = ""

        if (file.name.split('.').pop()=== 'msg') {
            Object.defineProperty(file, 'type', { value: 'application/vnd.ms-outlook' });
        }           

        done();
    }
},
init: function () {

    this.on("sending", function (file, xhr, data) {
            // This sets the Content-type for the request not just the
            // uploaded file i.e. one boundary of multipart/form-data

            // var send = xhr.send;
            // xhr.send = function () {
            //    xhr.setRequestHeader('Content-Type', file.type);                  
            //    send.call(xhr, file);
            // };
        }
}
Run Code Online (Sandbox Code Playgroud)

控制器

[HttpPost]
public ActionResult PostFile(HttpPostedFileBase file)
{
    // file.ContentType is application/octet-stream
}
Run Code Online (Sandbox Code Playgroud)