简体   繁体   English

Java - 带有大括号“()”的 Amazon S3 存储桶上传问题未上传

[英]Java - Amazon S3 bucket upload issue with braces “()” not uploading

I am trying to upload files on Amazon s3 bucket in a very simple way, but it gives error if the file name consists of "(" or ")", i dont want remove or replace these braces as they are required for my case我正在尝试以一种非常简单的方式在 Amazon s3 存储桶上上传文件,但如果文件名由“(”或“)”组成,则会出错,我不想删除或替换这些大括号,因为它们是我的案例所必需的

Code:代码:

AWSCredentials awsCredentials = new BasicAWSCredentials("accessKey", "secretKey");
        AmazonS3 s3 = new AmazonS3Client(awsCredentials);
        String fileName = "TEST_FILE_(NAME).pdf";
        String directorykey = "path/to/amazon/directory";
        File file =  new File(/* path_to_file + */ fileName);
        
        try {
            s3.putObject(bucketName, directorykey+"/"+fileName , file);
        } catch (AmazonServiceException e) {
            LOG.fatal("Failed to store file to bucket: " , e);
        } catch (AmazonClientException e) {
            LOG.fatal("Failed to store file to bucket: " , e);
        }

ERROR:错误:

Status Code: 403;状态码:403; Error Code: SignatureDoesNotMatch;错误代码:SignatureDoesNotMatch; Request ID: tx000000000000002e9edee-005a4ed3d2-2213a2-uky-campus-1;请求 ID:tx000000000000002e9edee-005a4ed3d2-2213a2-uky-campus-1; S3 Extended Request ID: 123456789) S3 扩展请求 ID:123456789)

Name of the file TEST_FILE_(NAME).pdf won't be used here - this is path to a local file,文件TEST_FILE_(NAME).pdf不会在这里使用 - 这是本地文件的路径,

S3 isn't actually a filesystem, it's more like a big (hash table) associative array. S3 实际上并不是一个文件系统,它更像是一个大的(哈希表)关联数组。 The "Bucket" is the name of the hash table, and the "Key" is the key ( from here ) “Bucket”是 hash 表的名称,“Key”是键( 来自这里

String fileName = "TEST_FILE_(NAME).pdf";
String directorykey = "path/to/amazon/directory";

// make sure, that the file exists in a location - provide a path to a file
File file =  new File(/* path_to_file + */ fileName);
try {
  s3.putObject(bucketName, directorykey + "/" + fileName , file);
} catch (AmazonServiceException e) {
  LOG.fatal("Failed to store file to bucket: " , e);
} catch (AmazonClientException e) {
  LOG.fatal("Failed to store file to bucket: " , e);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM