如何使用java将AWS中存在的文件从AWS EMR上传到EC2机器

时间:2016-04-12 06:37:02

标签: java amazon-s3 amazon-ec2 sftp amazon-emr

有没有办法将存储在AWS S3上的文件从EMR实例上传到另一个EC2实例目录。

到目前为止,我正在尝试使用java SFTP。还尝试使用AWS S3 Client将对象放入s3。

这是我的代码:

      try {
            String bucketName  = "my-bucket/product-images";
            BufferedImage image;
            URL url =new URL(product_image_url);
            image = ImageIO.read(url);
            String imageName = FilenameUtils.getBaseName(product_image_url);

            /*Tried creating new file in current directory*/
            File file = new File(imageName);
            ImageIO.write(image,"jpg",file);
            s3client.putObject(new PutObjectRequest(bucketName,imageName,file));


            /*Here passing source as file name created in current dir
             I have also tried giving bucket path as                 
             sftpChannel.put("s3://xwalker-images/product-images/"+imageName, imageName);
            */

            sftpChannel.put("imageName, "/my_images/"+imageName);
        } catch (SftpException e) {         
            e.printStackTrace();
        }

我在sftpChannel.put收到错误Nullpointer,因为imageName变为NULL。

有谁能告诉我哪里出错了? 我试过在本地机器上执行它,它工作正常。但是当我在AWS-EMR上运行它时失败了。 是否有可能在AWS S3中做我期望的事情?

0 个答案:

没有答案