Here you can find the source of extractFileNameFromContentDisposition(String contentDisposition)
Parameter | Description |
---|---|
contentDisposition | - the content-disposition header. Cannot be <code>null>/code>. |
null
if the content-disposition header does not contain the filename attribute.
public static final String extractFileNameFromContentDisposition(String contentDisposition)
//package com.java2s; //License from project: Apache License public class Main { /**// w ww . j a va 2 s . c om * Extract the file name from the content disposition header. * <p> * See <a * href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html">http: * //www.w3.org/Protocols/rfc2616/rfc2616-sec19.html</a> for detailled * information regarding the headers in HTML. * * @param contentDisposition * - the content-disposition header. Cannot be <code>null>/code>. * @return the file name, or <code>null</code> if the content-disposition * header does not contain the filename attribute. */ public static final String extractFileNameFromContentDisposition(String contentDisposition) { System.out.println("content disposition = " + contentDisposition); String[] attributes = contentDisposition.split(";"); for (String a : attributes) { if (a.toLowerCase().contains("filename")) { // The attribute is the file name. The filename is between // quotes. try { return a.substring(a.indexOf('\"') + 1, a.lastIndexOf('\"')); } catch (Exception e) { return a.substring(a.indexOf('=') + 1, a.length()); } } } // not found return null; } }