简体   繁体   中英

Where does strange MIME types come from?

I have a web service for uploading files written in C#. Front-end application is written in Javascript / HTML5 (using https://github.com/blueimp/jQuery-File-Upload )

Recently, I was reviewing server logs and found some strange MIME types for PDF files that where sent by client browser, for example:

application/unknown
application/force-download
application/force-download/n
application/force-download\n
[application/pdf]

Some of them are causing .NET framework throwing exception:

MultipartMemoryStreamProvider streamProvider = new MultipartMemoryStreamProvider();
await Request.Content.ReadAsMultipartAsync(streamProvider); 

"Message Error parsing MIME multipart body part header byte 156 of data segment System.Byte[]."

I don't have a clue what to do with that.

Try checking the Content-Type in the request.

Content-Disposition:  
form-data;  
name="imagefile";  
filename="C:\Users\Pictures\sid.png"  
Content-Type:  

(notice the blank Content-Type, it should be Content-Type: image/png )

// within WebAPI you can use code below to log the request body
string requestBody = await Request.Content.ReadAsStringAsync();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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