尝试从我的Java Spring应用程序上传文件到Amazon S3时出现异常。方法很简单:AWS Java S3上传错误:“配置文件不能为空”
private void productionFileSaver(String keyName, File f) throws InterruptedException {
String bucketName = "{my-bucket-name}";
TransferManager tm = new TransferManager(new ProfileCredentialsProvider());
// TransferManager processes all transfers asynchronously,
// so this call will return immediately.
Upload upload = tm.upload(
bucketName, keyName, new File("/mypath/myfile.png"));
try {
// Or you can block and wait for the upload to finish
upload.waitForCompletion();
System.out.println("Upload complete.");
} catch (AmazonClientException amazonClientException) {
System.out.println("Unable to upload file, upload was aborted.");
amazonClientException.printStackTrace();
}
}
它基本上是相同的,亚马逊提供here,并试图this other版本时完全相同的消息(“配置文件不能为空”)相同的异常出现。 该问题与文件不存在或为空无关(我已经用千种方法检查了在调用它之前存在的TransferManager.upload
方法存在的File参数)。
我找不到有关我的异常消息“配置文件不能为空”的任何信息。错误日志的第一线如下:
com.amazonaws.AmazonClientException: Unable to complete transfer: profile file cannot be null
at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.unwrapExecutionException(AbstractTransfer.java:281)
at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.rethrowExecutionException(AbstractTransfer.java:265)
at com.amazonaws.services.s3.transfer.internal.AbstractTransfer.waitForCompletion(AbstractTransfer.java:103)
at com.fullteaching.backend.file.FileController.productionFileSaver(FileController.java:371)
at com.fullteaching.backend.file.FileController.handlePictureUpload(FileController.java:247)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
我的S3政策允许获取和puttings对象为所有类型的用户。
想知道发生了什么?
谢谢。 'Lambda'中同样的事情是,我将'ProfileCredentialsProvider'传递给导致该错误的构造函数。使用'AmazonS3 s3Client =新的AmazonS3Client();'工作。 –
仅供参考 - 我在Docker ECS容器中遇到此问题。这与Lambda一样。在你的代码中查找'新的ProfileCredentialsProvider(someProfile))'并用'DefaultAWSCredentialsProviderChain.getInstance()'替换它' –
我在这里留下了一个代码示例的答案:http://stackoverflow.com/questions/41796355/aws-error-下载对象,从-S3-轮廓文件不能-是空/ 44079772#44079772 –