use of io.jmix.core.FileRef in project jmix-docs by Haulmont.
the class FileStorageUploadFieldScreen method onManuallyControlledFieldFileUploadSucceed.
@Subscribe("manuallyControlledField")
public void onManuallyControlledFieldFileUploadSucceed(SingleFileUploadField.FileUploadSucceedEvent event) {
// <1>
File file = temporaryStorage.getFile(manuallyControlledField.getFileId());
if (file != null) {
notifications.create().withCaption("File is uploaded to temporary storage at " + file.getAbsolutePath()).show();
}
// <2>
// <3>
FileRef fileRef = temporaryStorage.putFileIntoStorage(manuallyControlledField.getFileId(), event.getFileName());
manuallyControlledField.setValue(fileRef);
notifications.create().withCaption("Uploaded file: " + manuallyControlledField.getFileName()).show();
}
use of io.jmix.core.FileRef in project jmix-docs by Haulmont.
the class ImageScreen method onInit.
// end::set-source[]
// end::listener[]
// tag::value-source[]
// tag::set-source[]
// tag::listener[]
@Subscribe
public void onInit(InitEvent event) {
// end::listener[]
// end::set-source[]
personsTable.addGeneratedColumn("image", entity -> {
Image<FileRef> image = uiComponents.create(Image.NAME);
image.setValueSource(new ContainerValueSource<>(personsTable.getInstanceContainer(entity), "image"));
image.setHeight("100px");
image.setScaleMode(Image.ScaleMode.CONTAIN);
return image;
});
// end::value-source[]
// tag::set-source[]
String address = "https://www.cuba-platform.com/sites/all/themes/cuba_adaptive/img/upper-header-logo.png";
URL url = null;
try {
url = new URL(address);
programmaticImage.setSource(UrlResource.class).setUrl(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
// end::set-source[]
// tag::listener[]
// tag::value-source[]
// tag::set-source[]
}
use of io.jmix.core.FileRef in project jmix by jmix-framework.
the class LocalFileStorage method saveStream.
@Override
public FileRef saveStream(String fileName, InputStream inputStream) {
Path relativePath = createRelativeFilePath(fileName);
FileRef fileRef = new FileRef(storageName, pathToString(relativePath), fileName);
saveStream(fileRef, inputStream);
return fileRef;
}
use of io.jmix.core.FileRef in project jmix by jmix-framework.
the class FileDownloadController method downloadFile.
@GetMapping
public void downloadFile(@RequestParam String fileRef, @RequestParam(required = false) Boolean attachment, HttpServletResponse response) {
checkFileDownloadPermission();
try {
FileRef fileReference;
fileReference = FileRef.fromString(fileRef);
fileTransferService.downloadAndWriteResponse(fileReference, fileReference.getStorageName(), attachment, response);
} catch (IllegalArgumentException e) {
throw new RestAPIException("Invalid file reference", String.format("Cannot convert '%s' into valid file reference", fileRef), HttpStatus.BAD_REQUEST, e);
}
}
use of io.jmix.core.FileRef in project jmix by jmix-framework.
the class FileStorageUploadFieldImpl method saveFile.
protected void saveFile(String fileName) {
checkFileStorageInitialized();
switch(mode) {
case MANUAL:
internalValueChangedOnUpload = true;
// FileRef should be set manually after uploading file into storage
setValue(null);
setValueToPresentation(fileName);
internalValueChangedOnUpload = false;
break;
case IMMEDIATE:
FileRef fileRef = temporaryStorage.putFileIntoStorage(fileId, fileName, fileStorage);
setValue(fileRef);
break;
}
}
Aggregations