java - getContentType method returning always 'application/force-download' -


i have url file can download. looks this:

 http://<server>/recruitment-mantis/plugin.php?page=bugsynchronizer/getfile&fileid=139&filehash=3e7a52a242f90c23539a17f6db094d86 

how content type of file? have admin in case simple:

   url url = new url(stringurl);     urlconnection urlconnection = url.openconnection();    urlconnection.connect();     string urlcontent = urlconnection.getcontenttype(); 

returning me application/force-download content type in every file (no matter jpg or pdf file). want cause want set extension of downloaded file (which can various). how 'get around' of application/force-download content type? in advance help.

check urlconnection.getheaderfield("content-disposition") filename. header used attachments in multipart content, doesn't hurt check.

if header not present, can save url temporary file, , use probecontenttype meaningful mime type:

path tempfile = files.createtempfile(null, null); try (inputstream urlstream = urlconnection.getinputstream()) {     files.copy(urlstream, tempfile, standardcopyoption.replace_existing); } string mimetype = files.probecontenttype(tempfile); 

be aware probecontenttype may return null if can't determine type of file.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -