Search in sources :

Example 6 with StoredFile

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);
}
Also used : AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) AjaxFormSubmitBehavior(org.apache.wicket.ajax.form.AjaxFormSubmitBehavior) Form(org.apache.wicket.markup.html.form.Form) StoredFile(org.apache.openmeetings.util.StoredFile) UploadProgressBar(org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar) File(java.io.File) StoredFile(org.apache.openmeetings.util.StoredFile) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Aggregations

File (java.io.File)6 StoredFile (org.apache.openmeetings.util.StoredFile)6 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)4 FileUtils.copyInputStreamToFile (org.apache.commons.io.FileUtils.copyInputStreamToFile)2 IOException (java.io.IOException)1 RoomFile (org.apache.openmeetings.db.entity.room.RoomFile)1 ProcessResult (org.apache.openmeetings.util.process.ProcessResult)1 ProcessResultList (org.apache.openmeetings.util.process.ProcessResultList)1 UnsupportedFormatException (org.apache.tika.exception.UnsupportedFormatException)1 AjaxRequestTarget (org.apache.wicket.ajax.AjaxRequestTarget)1 AjaxFormSubmitBehavior (org.apache.wicket.ajax.form.AjaxFormSubmitBehavior)1 UploadProgressBar (org.apache.wicket.extensions.ajax.markup.html.form.upload.UploadProgressBar)1 Form (org.apache.wicket.markup.html.form.Form)1 FileUpload (org.apache.wicket.markup.html.form.upload.FileUpload)1