public void performUpload(File uploadedFile, String originalFileName,
String bucket, String key, String mimeType,
ERS3Attachment attachment) throws MalformedURLException,
IOException {
try {
AWSAuthConnection conn = attachment.awsConnection();
FileInputStream attachmentFileInputStream = new FileInputStream(
uploadedFile);
BufferedInputStream attachmentInputStream = new BufferedInputStream(
attachmentFileInputStream);
try {
S3StreamObject attachmentStreamObject = new S3StreamObject(
attachmentInputStream, null);
Map<String, List<String>> headers = new TreeMap<String, List<String>>();
headers.put("Content-Type",
Arrays.asList(new String[] { mimeType }));
headers.put("Content-Length", Arrays
.asList(new String[] { String.valueOf(uploadedFile
.length()) }));
headers.put("x-amz-acl",
Arrays.asList(new String[] { attachment.acl() }));
if (originalFileName != null) {
headers.put("Content-Disposition", Arrays
.asList(new String[] { "attachment; filename="
+ originalFileName }));
}
Response response = conn.putStream(bucket, key,
attachmentStreamObject, headers);
if (failed(response)) {
throw new IOException("Failed to write '" + bucket + "/"
+ key + "' to S3: Error "
+ response.connection.getResponseCode() + ": "