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-type
  3. 执行 1. & 2(如果文件不以 .jpg 结尾,则拒绝上传,否则允许上传并重新检查上传的文件及其 mime 类型)
于 2013-12-06T13:57:04.750 回答