Amazon S3客户端通过代理连接 – putObject获取NullPointerException

我有这段简单的代码试图通过代理将文件上传到Amazon S3.这是代码:

BasicAWSCredentials basicCred = new BasicAWSCredentials("my_access_key", "my_secret_key");
    ClientConfiguration clientCfg = new ClientConfiguration();
    clientCfg.setProtocol(Protocol.HTTP);

    //setup proxy connection:
    clientCfg.setProxyHost("192.168.2.12");
    clientCfg.setProxyPort(80);




    AmazonS3 s3 = new AmazonS3Client(basicCred, clientCfg);


    String bucketName = "mybucket";
    String key = "/test/Capture.JPG";
    File file = new File("d:/Test_Data/Capture.JPG");

    System.out.println("Uploading a new object to S3 from a file");
    s3.putObject(new PutObjectRequest(bucketName, key, file));

但是这是我从运行程序时得到的错误:

Exception in thread "main" java.lang.NullPointerException
    at com.amazonaws.util.BinaryUtils.fromHex(BinaryUtils.java:69)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1066)
    at javaapplication8.JavaApplication8.main(JavaApplication8.java:48)
Java Result: 1

我正在使用来自亚马逊的最新aws 1.3.8 sdk.代理设置在我旁边的另一台PC上,它只是一个简单的Javascript代理(http://www.catonmat.net/http-proxy-in-nodejs/)

我无法弄明白为什么.有人可以帮帮我吗?

这是另一种方法,

ClientConfiguration config = new ClientConfiguration();
config.setProtocol(Protocol.HTTPS);
config.setProxyHost("YOUR_PROXY_IP");
config.setProxyPort(YOUR_PROXY_PORT);

BasicAWSCredentials creds = new BasicAWSCredentials("YOUR_KEY", "YOUR_SECRET"); 
s3Client = AmazonS3ClientBuilder.standard()
                .withClientConfiguration(config)
                .withRegion(Regions.US_EAST_2)
                .withCredentials(new AWSStaticCredentialsProvider(creds))                   
                .build();
相关文章
相关标签/搜索