java - How to know what is the real content type of the part in multipart request -


i sending multipart request client server this:

filebody file2 = new filebody(new file("./test2.txt")); filebody image1 = new filebody(new file("./dsc_0064.jpg")); 

and see, 1 of files txt, , 1 if jpg image.

on server, receive request , take headers each part, , this:

------------part 1------------ content-disposition=form-data; name="test2"; filename="test2.txt" content-type=application/octet-stream content-transfer-encoding=binary ------------part 2------------ content-disposition=form-data; name="image1"; filename="dsc_0064.jpg" content-type=application/octet-stream content-transfer-encoding=binary 

as see, content type both of them application/octet-stream. how determine in dynamic environment actual type? image? text? video?

i can't depend on file name because user can change example txt png , server think image exception because of that.

that's because not setting mime type. can other constructor filebody(file, contenttype) takes content type:

filebody file2 = new filebody(new file("./test2.txt"), contenttype.text_plain); filebody image1 = new filebody(new file("./dsc_0064.jpg"), contenttype.create("image/jpeg")); 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -