【发布时间】:2013-12-22 16:08:36
【问题描述】:
我正在创建一个应用程序,并且我有一张客户的图片。如何获取此图像并上传到 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;
}
}
有什么想法吗?
谢谢
【问题讨论】:
-
分享一些无效的细节。澄清一下:您想在图像上传到“webapp服务器”后将图像上传到ftp服务器吗?
-
@nexus,客户何时选择您的图片而不是将其插入到我的数据库中,我认为最好将他的图片发送到 ftp,并在我的数据库中仅插入其名称并将您的图片引用到您的电子邮件中。
-
我只是想知道:你真的需要 ftp 服务器吗?你的数据库和你的网络服务器在同一台机器上吗?如果是,你真的还需要 ftp 服务器吗?
-
@nexus 我需要这项工作,在 ftp 或其他方式上。我不想在我的数据库中插入客户图像。如果我将图像上传到路径 /home/myapp/images 上的网络服务器,您会怎么想?
标签: java frameworks vaadin vaadin7