简体   繁体   中英

Filename with extension from mime string

I have mime as a string and httpheader how can i get the file name with extension from the http header or simply is there any way to get extension from mime?

Eg: MIME,Extension

 `application/octet-stream  class`
 `application/octet-stream  dms`
` application/octet-stream  exe`
 `application/octet-stream  lha`

the above has same mime string but different extensions

These are the things which i get from httpHeader for a zip file

Keep-Alive : timeout=10

Connection : Keep-Alive

Age : 4418

Accept-Ranges : bytes

ETag : "ee0043-157f-4acf6ff5c1640"

Cache-Control : max-age=10800, s-maxage=10800

x-mii-cache-hit : 1

X-Pb-Mii : Powered by Mirror Image Internet

Via : 1.1 sjc005158 (MII-APC/2.3), 1.1 sjc005112 (MII-APC/2.3)

Content-Length : 5503

Last-Modified : Thu, 15 Sep 2011 08:52:33 GMT

Date : Tue, 26 Nov 2013 08:30:27 GMT

Content-Type : application/zip

Server : MII-APC/2.4.5

I guess you could if you really wanted to using a list like this but maybe it's not the best way.

Another approach is to use Content Disposition header if it's available:

    Content-Disposition: attachment; filename=Myfile.txt

And then parse the file name and extension from there

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