[英]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.