簡體   English   中英

將圖片上傳到ftp嗎?

[英]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示例)?

你可以

  1. 快速又骯臟:只需檢查文件名是否以.jpg結尾
  2. 確定上傳文件的MIME類型
  3. 執行1.和2(如果文件不以.jpg結尾,則拒絕上載,否則允許上載並使用mime類型重新檢查上載的文件)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM