Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 242
Mateusz Puwałowski Avatar asked Nov 09 '22 18:11

Mateusz Puwałowski


1 Answers

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();
like image 144
syed Avatar answered Nov 15 '22 08:11

syed