上传图片到ftp?

时间:2013-12-05 16:00:57

标签: java frameworks vaadin vaadin7

我正在创建一个应用程序,我有一个客户的图像。如何获取此图像并上传到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;

    }
}

有什么想法吗?

感谢

1 个答案:

答案 0 :(得分:0)

根据评论中的对话提供答案:

使用Vaadin上传组件将图像上传到服务器上的文件夹。

  

您知道如何检查上传时的扩展程序,仅示例.jpg吗?

你可以

  1. 快速&脏:只检查文件名是否以.jpg结尾
  2. Determine上传文件的mime类型
  3. 做1.& 2(如果文件没有以.jpg结尾,则拒绝上传,否则允许上传并使用其mime类型重新检查上传的文件)
相关问题