4

我正在尝试使用 Java SDK 将文件上传到 s3。该代码在我的运行 jdk1.6.0_26 的 Windows 7 机器上运行良好,但是当在服务器上运行时,Ubuntu Server 10.04 with Java(TM) SE Runtime Environment (build 1.7.0-b147),我收到以下错误,这似乎是来自https://github.com/amazonwebservices/aws-sdk-for-java/blob/master/src/main/java/com/amazonaws/auth/AbstractAWSSigner.java

com.amazonaws.AmazonClientException: Unable to calculate a request signature: null Stack trace : com.amazonaws.auth.AbstractAWSSigner.signAndBase64Encode(AbstractAWSSigner.java:71)
com.amazonaws.auth.AbstractAWSSigner.signAndBase64Encode(AbstractAWSSigner.java:55)
com.amazonaws.services.s3.internal.S3Signer.sign(S3Signer.java:101)
com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:234)
com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:169)
com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2597)
com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1025)

对 s3 的调用:

AWSCredentials c = new BasicAWSCredentials(accessKey, secretKey);
AmazonS3Client client = new AmazonS3Client(c);
String key = station + "/" + file.getName();        
client.putObject(new PutObjectRequest(bucket, key, file));      

我是 Java 新手,不知道如何进一步排除故障。

4

1 回答 1

3

我的直觉是您在服务器上使用的 JDK/JRE 没有正确的 crypo/JCE。要么安装高加密包,要么安装包含正确密码的新 JDK/JRE。

Java Cryptography Extension 可以在底部下载: http ://www.oracle.com/technetwork/java/javase/downloads/index.html

于 2012-04-24T16:28:13.640 回答