BasicHeader header = new BasicHeader("Content-Disposition", "attachment; filename=blah.txt"); HeaderElement[] helelms = header.getElements(); if (helelms.length > 0) { HeaderElement helem = helelms[0]; if (helem.getName().equalsIgnoreCase("attachment")) { NameValuePair nmv = helem.getParameterByName("filename"); if (nmv != null) { System.out.println(nmv.getValue()); } } }
/** * Get a map of parameters from the Content-Disposition header if present * * @return map of Content-Disposition parameters or null */ public Map<String, String> getContentDisposition() { if (contentDisposition == null && headers.containsKey(CONTENT_DISPOSITION)) { final List<String> values = headers.get(CONTENT_DISPOSITION); if (values.isEmpty()) { return null; } contentDisposition = new HashMap<>(); final String value = values.get(0); final BasicHeader header = new BasicHeader(CONTENT_DISPOSITION, value); for (final HeaderElement headEl : header.getElements()) { for (final NameValuePair pair : headEl.getParameters()) { contentDisposition.put(pair.getName(), pair.getValue()); } } } return contentDisposition; } }