Having trouble finding some example开发者_如何学Pythons showing how I can use Java to allow users to upload an image to Amazon S3.
The flow is:
User is on HTML form with file input form element.
This form submits the selected image to a Servlet.
This Servlet processes the image and stores it in S3.
Anyone know of any good links/tutorials that outline sample code to perform this?
For the 3rd point:
- Grab jets3t
It's tutorial is simple. Here's a snippet I'm using:
S3Object fileObject = new S3Object(path); fileObject.setDataInputStream(is); s3service.putObject(bucketName, fileObject);
For the previous two points - look at this question
Recommend you to use html amazon API to do this. Streaming is a bit complex and in most cases you do not need it.
You can also use a simple form to uploda the file to the S3 Bucket. Look at this example http://aws.amazon.com/articles/1434
Example form:
<html>
<head>
<title>S3 POST Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<form action="https://s3-bucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="uploads/${filename}">
<input type="hidden" name="AWSAccessKeyId" value="YOUR_AWS_ACCESS_KEY">
<input type="hidden" name="acl" value="private">
<input type="hidden" name="success_action_redirect" value="http://localhost/">
<input type="hidden" name="policy" value="YOUR_POLICY_DOCUMENT_BASE64_ENCODED">
<input type="hidden" name="signature" value="YOUR_CALCULATED_SIGNATURE">
<input type="hidden" name="Content-Type" value="image/jpeg">
<!-- Include any additional input fields here -->
File to upload to S3:
<input name="file" type="file">
<br>
<input type="submit" value="Upload File to S3">
</form>
</body>
</html>
精彩评论