Serving varied content from Amazon S3
One question that I see a lot is "How do I get my file of type 'blah' to be served properly from S3?"
The answer, it turns out is fairly simple. Each object in S3 has metadata associated with it. When you upload the file, you can set that metadata, including the Content-Type header. For example, XML files use; Content-Type: text/xml
If you have something like an .swf file, you'd use;
or for a mp4 video file;
To do this using the Jets3t java client, you'd write some code that looks like this;
RestS3Service s3 = getS3Service();
S3Bucket bucket = new S3Bucket(bucketName);
S3Object obj = new S3Object(bucket, objectId);
obj = s3.putObject(bucket, obj);
This code also sets the content length, so the file being uploaded is streamed to S3, not buffered in memory.
Jets3t also has a pretty handy class: org.jets3t.service.utils.Mimetypes, which helps you get the mime type for a given file or filename.