I am using Dropzone.js to upload a file with an .msg
extension and a MIME type of application/vnd.ms-outlook
.
When I select a file with a .msg
extension the file type is empty.
This can be fixed by implementing an accept
function and setting the file type
however, when the request is sent the MIME type is set to application/octet-stream
which is the default when the content type
is unknown or empty.
Question
How can I set the Content-Type
for the file e.g. MyFile.msg in the multipart/form-data;
to application/vnd.ms-outlook
?
Request
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
Dropzone
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);
// };
}
}
Controller
[HttpPost]
public ActionResult PostFile(HttpPostedFileBase file)
{
// file.ContentType is application/octet-stream
}