in src/main/java/org/apache/sling/servlets/post/impl/helper/SlingFileUploadHandler.java [519:559]
public void setFile(final Resource parent, final RequestProperty prop, final List<Modification> changes)
throws PersistenceException {
for (final RequestParameter value : prop.getValues()) {
// ignore if a plain form field or empty
if (value.isFormField() || value.getSize() <= 0) {
continue;
}
// get node name
String name = prop.getName();
if (name.equals("*")) {
name = value.getFileName();
// strip of possible path (some browsers include the entire path)
name = name.substring(name.lastIndexOf('/') + 1);
name = name.substring(name.lastIndexOf('\\') + 1);
}
name = Text.escapeIllegalJcrChars(name);
// get content type
String contentType = value.getContentType();
if (contentType != null) {
int idx = contentType.indexOf(';');
if (idx > 0) {
contentType = contentType.substring(0, idx);
}
}
if (contentType == null || contentType.equals(MT_APP_OCTET)) {
// try to find a better content type
final ServletContext ctx = this.servletContext;
if (ctx != null) {
contentType = ctx.getMimeType(value.getFileName());
}
if (contentType == null) {
contentType = MT_APP_OCTET;
}
}
this.setFile(parent, prop, value, changes, name, contentType);
}
}