use of org.apache.openmeetings.util.StoredFile in project openmeetings by apache.
the class UploadableImagePanel method onInitialize.
@Override
protected void onInitialize() {
super.onInitialize();
final Form<Void> form = new Form<>("form");
form.setMultiPart(true);
form.setMaxSize(Bytes.bytes(getMaxUploadSize()));
// Model is necessary here to avoid writing image to the User object
form.add(fileUploadField);
form.add(new UploadProgressBar("progress", form, fileUploadField));
fileUploadField.add(new AjaxFormSubmitBehavior(form, "change") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
FileUpload fu = fileUploadField.getFileUpload();
if (fu != null) {
File temp = null;
try {
temp = fu.writeToTempFile();
StoredFile sf = new StoredFile(fu.getClientFileName(), temp);
if (sf.isImage()) {
processImage(sf, temp);
}
} catch (Exception e) {
log.error("Error", e);
} finally {
if (temp != null && temp.exists()) {
log.debug("Temp file was deleted ? {}", temp.delete());
}
fu.closeStreams();
fu.delete();
}
}
update();
target.add(profile, form);
}
});
add(form.setOutputMarkupId(true));
add(BootstrapFileUploadBehavior.INSTANCE);
}
Aggregations