[英]Upload image to ftp?
我正在创建一个应用程序,并且有我的客户的图片。 如何获取此图像并上传到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;
}
}
任何想法 ?
谢谢
根据评论中的对话提供答案:
像以前一样,使用Vaadin的上载组件将图像上载到服务器上的文件夹。
您知道如何检查上传时的扩展名吗(仅.jpg示例)?
你可以
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.