在Java中使用ContentDisposition进行URLEncoding UTF-8文件名时出现AWS Signa



我试图将文件上传到S3并使用Amazon SDK的ObjectMetadata.setContentDisposition()对文件名进行urlencode。文件名可以包含任何UTF-8字符和空格。现在文件名在空格上有断点,当使用特殊字符时,我得到一个错误。

我使用它的代码片段如下:

ObjectMetadata fileMetadata = new ObjectMetadata();
fileMetadata.setContentLength(file.length());
fileMetadata.setContentType(metaContentType);
fileMetadata.addUserMetadata("Filename", metaFileName); 
fileMetadata.setContentDisposition("attachment; filename*=UTF-8 " + URLEncoder.encode(metaFileName,"UTF-8"));  

不幸的是,这并没有像我得到的异常一样工作:"AmazonS3Exception:状态代码:403,AWS服务:AmazonS3, AWS请求ID: 3F2C3AE3420561BA, AWS错误代码:SignatureDoesNotMatch, AWS错误消息:我们计算的请求签名与您提供的签名不匹配。请检查您的密钥和签名方法。

完整的堆栈跟踪:

at services.AWS_S3_Uploader.AWS_S3_Upload.service(AWS_S3_Upload.java:281)
    at com.sonicsw.xqimpl.service.ServiceMessageHandler.callService(ServiceMessageHandler.java:461)
    at com.sonicsw.xqimpl.service.ServiceMessageHandler.handleMessageCommon(ServiceMessageHandler.java:273)
    at com.sonicsw.xqimpl.service.ServiceMessageHandler.handleMessage(ServiceMessageHandler.java:136)
    at com.sonicsw.xqimpl.service.XQDispatcher.onMessage(XQDispatcher.java:460)
    at com.sonicsw.esb.itinerary.model.EsbStepNode.doExecute(EsbStepNode.java:296)
    at com.sonicsw.esb.itinerary.model.EsbStepNode.execute(EsbStepNode.java:180)
    at com.sonicsw.esb.process.model.impl.DefaultActivityNode.offerIncoming(DefaultActivityNode.java:140)
    at com.sonicsw.esb.itinerary.engine.ItineraryEngine.executeProcess(ItineraryEngine.java:338)
    at com.sonicsw.esb.itinerary.engine.ItineraryEngine.handleToken(ItineraryEngine.java:181)
    at com.sonicsw.esb.itinerary.engine.ItineraryEngine.handleMessage(ItineraryEngine.java:171)
    at com.sonicsw.xqimpl.endpoint.container.EndpointContextContainer.onMessage(EndpointContextContainer.java:116)
    at com.sonicsw.xq.connector.jms.JMSEndpointMessageListener.onMessage(JMSEndpointMessageListener.java:259)
    at progress.message.jimpl.Session.deliver(Session.java:3086)
    at progress.message.jimpl.Session.run(Session.java:2489)
    at progress.message.jimpl.Session$SessionThread.run(Session.java:2881)
Caused by: java.lang.Exception: AmazonServiceException
    at services.AWS_S3_Uploader.AWS_S3.logAmazonServiceException(AWS_S3.java:340)
    at services.AWS_S3_Uploader.AWS_S3.uploadObject(AWS_S3.java:280)
    at services.AWS_S3_Uploader.AWS_S3_Upload.service(AWS_S3_Upload.java:263)
    ... 15 more
Caused by: AmazonS3Exception: Status Code: 403, AWS Service: Amazon S3, AWS Request ID: 3F2C3AE3420561BA, AWS Error Code: SignatureDoesNotMatch, AWS Error Message: The request signature we calculated does not match the signature you provided. Check your key and signing method., S3 Extended Request ID: 0AlM9giKI8hRMWG0Xc84lxXSJ8ZwUPB2DjHKddwa1oVZ4AWUzlyko7jEko9MEtwkd5Tc7xocFJw=
    at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:644)
    at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:338)
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:190)
    at com.amazonaws.services.s3.AmazonS3Client.invoke(AmazonS3Client.java:2979)
    at com.amazonaws.services.s3.AmazonS3Client.putObject(AmazonS3Client.java:1159)
    at com.amazonaws.services.s3.transfer.internal.UploadCallable.uploadInOneChunk(UploadCallable.java:97)
    at com.amazonaws.services.s3.transfer.internal.UploadCallable.call(UploadCallable.java:89)
    at com.amazonaws.services.s3.transfer.internal.UploadMonitor.upload(UploadMonitor.java:179)
    at com.amazonaws.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:137)
    at com.amazonaws.services.s3.transfer.internal.UploadMonitor.call(UploadMonitor.java:48)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)

我正在使用:
Java 1.6
aws-java-sdk-1.10.2.jar

欢迎所有的帮助和建议。如果需要更多的信息,尽管问。

Br .

我不知道这是否是原因,但用于filename*的编码是不正确的。

相关内容

  • 没有找到相关文章

最新更新