2

I am uploading some files to the S3 buckets. One zip file, one .json file.

When I upload them, both files will have:

Content-Type: application/octet-stream

I need the zip files to have:

Content-Type: text/plain
Content-Encoding: gzip

What do I have to do to make sure that these files are uploaded with the desired type/encoding?

Below is some of my code:

Saving the file:

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName)));
bw.write(content);
bw.close();

Uploading the file:

AWSCredentials myCredentials = new BasicAWSCredentials(ACCESS_KEY,SECRET_KEY);
TransferManager tx = new TransferManager(myCredentials);
Upload uploading = tx.upload(new PutObjectRequest(bucket, awsFileKey, file));

What I am trying to accomplish:

I am working on an auto-suggest feature. If I upload plain json file, it is over 1.5MB, which is terrible. So next best thing is to upload the ZIP file(it reduces the file to 300kb, decent) then when user loads the page, browser should unzip. Some reason only setting the content type/encoding to those specified works, everything else fails.

iCodeLikeImDrunk
  • 17,085
  • 35
  • 108
  • 169
  • Those requirements are probably wrong. You do not want to set those headers if you really have ZIP files. Why do you think you need those header types? – schlenk May 20 '13 at 23:01
  • added what i am trying to accomplish in main post – iCodeLikeImDrunk May 20 '13 at 23:04
  • @schlenk i set those headers when playing around with the type/encoding in s3, somehow it worked. i know it looks super stupid that im setting type to text/plain when im obviously trying to get a zip file =/ – iCodeLikeImDrunk May 21 '13 at 02:33

1 Answers1

3

ObjectMetadata. Make new then set the metadata you want.

PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, awsFileKey, file);

if (metadata != null) {
    putObjectRequest.setMetadata(metadata);
}
iCodeLikeImDrunk
  • 17,085
  • 35
  • 108
  • 169