我正在创建一个应用程序,并且我有一张客户的图片。如何获取此图像并上传到 ftp ?
在上传章节中阅读 vaadin7 书我确实做了示例但没有工作,我也在寻找如何将此图像图片发送到 ftp。
我确实试过这个。
/** My UI */
//foto
Image picture = new Image();
picture.setWidth("128px");
picture.setHeight("128px");
mainLayout.addComponent(foto);
//upload image picture
ImageUpload imageUp = new ImageUpload(picture);
Upload upload = new Upload();
upload.setCaption("Find your picture");
upload.setButtonCaption("Send");
upload.addSucceededListener(imageUp);
mainLayout.addComponent(upload);
/** class upload image picture */
public class ImageUpload implements Receiver, SucceededListener{
private File file;
private Image image;
public ImageUpload(Image image){
this.image = image;
this.image.setVisible(false);
}
@Override
public void uploadSucceeded(SucceededEvent event) {
this.image.setVisible(true);
this.image.setSource(new FileResource(file));
}
@Override
public OutputStream receiveUpload(String filename, String mimeType) {
FileOutputStream fos = null;
try{
file = new File("/tmp/" + filename);
fos = new FileOutputStream(file);
}catch(final java.io.FileNotFoundException ex){
new Notification("File not found \n",
ex.getLocalizedMessage(),
Notification.Type.ERROR_MESSAGE)
.show(Page.getCurrent());
}
return fos;
}
}
任何想法 ?
谢谢