Estoy usando Dropzone.js para cargar un archivo con una extensión .msg
y un tipo MIME de application/vnd.ms-outlook
.
Cuando selecciono un archivo con una extensión .msg
, el tipo de archivo está vacío.
Esto se puede solucionar implementando una función de accept
y configurando el tipo de archivo; sin embargo, cuando se envía la solicitud, el tipo MIME se establece en application/octet-stream
que es el valor predeterminado cuando el tipo de contenido es desconocido o está vacío.
Pregunta
¿Cómo puedo configurar el Content-Type
para el archivo, por ejemplo, MyFile.msg en multipart/form-data;
a application/vnd.ms-outlook
?
Solicitud
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
Zona de descenso
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 ie one boundary of multipart/form-data // var send = xhr.send; // xhr.send = function () { // xhr.setRequestHeader('Content-Type', file.type); // send.call(xhr, file); // }; } }
Controlador
[HttpPost] public ActionResult PostFile(HttpPostedFileBase file) { // file.ContentType is application/octet-stream }