0

アプリケーションを作成していて、顧客のイメージ写真があります。この画像を取得して 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;

    }
}

何か案が ?

ありがとう

4

1 に答える 1

0

コメントでの会話に従って回答を提供するには:

Vaadin のアップロード コンポーネントを使用して、サーバー上のフォルダーに画像をアップロードします。

アップロード時に拡張子を確認する方法を知っていますか?例のみ .jpg ?

あなたは出来る

  1. クイック&ダーティ:ファイル名が.jpgで終わるかどうかを確認するだけです
  2. アップロードされたファイルの MIME タイプを決定する
  3. 1. & 2 (ファイルが .jpg で終わらない場合はアップロードを拒否し、それ以外の場合はアップロードを許可し、アップロードされたファイルを MIME タイプで再チェックします)
于 2013-12-06T13:57:04.750 に答える