use of files.ex1.entity.Attachment in project jmix-docs by Haulmont.
the class AttachmentBrowse method onSaveImageBtnClick.
@Subscribe("saveImageBtn")
public void onSaveImageBtnClick(Button.ClickEvent event) {
Attachment attachment = attachmentsTable.getSingleSelected();
if (attachment == null)
return;
saveToLocalFile(attachment, Paths.get("."));
}
use of files.ex1.entity.Attachment in project jmix-docs by Haulmont.
the class AttachmentBrowse method attachmentsTableFileColumnGenerator.
@Install(to = "attachmentsTable.fileName", subject = "columnGenerator")
private Component attachmentsTableFileColumnGenerator(Attachment attachment) {
if (attachment.getFile() != null) {
LinkButton linkButton = uiComponents.create(LinkButton.class);
linkButton.setAction(new BaseAction("download").withCaption(attachment.getFile().getFileName()).withHandler(actionPerformedEvent -> downloader.download(attachment.getFile())));
return linkButton;
} else {
return new Table.PlainTextCell("<empty>");
}
}
use of files.ex1.entity.Attachment in project jmix-docs by Haulmont.
the class AttachmentBrowse method getAndSaveImage.
private void getAndSaveImage() {
try {
// <2>
URLConnection connection = new URL("https://picsum.photos/300").openConnection();
try (InputStream responseStream = connection.getInputStream()) {
// <3>
FileStorage fileStorage = fileStorageLocator.getDefault();
FileRef fileRef = fileStorage.saveStream("photo.jpg", responseStream);
// <4>
Attachment attachment = dataManager.create(Attachment.class);
attachment.setFile(fileRef);
dataManager.save(attachment);
}
} catch (IOException e) {
throw new RuntimeException("Error getting image", e);
}
}
Aggregations