我正在创建一个应用程序,我有一个客户的图像。如何获取此图像并上传到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;
}
}
有什么想法吗?
感谢
答案 0 :(得分:0)
根据评论中的对话提供答案:
使用Vaadin上传组件将图像上传到服务器上的文件夹。
您知道如何检查上传时的扩展程序,仅示例.jpg吗?
你可以