Java图像上传存储在Amazon S3中

发布于 2024-12-04 12:09:13 字数 239 浏览 0 评论 0原文

无法找到一些示例来展示我如何使用 Java 来允许用户将图像上传到 Amazon S3。

流程是:

  1. 用户位于带有文件输入表单元素的 HTML 表单上。

  2. 此表单将选定的图像提交到 Servlet。

  3. 此 Servlet 处理图像并将其存储在 S3 中。

有人知道任何好的链接/教程概述了执行此操作的示例代码吗?

Having trouble finding some examples showing how I can use Java to allow users to upload an image to Amazon S3.

The flow is:

  1. User is on HTML form with file input form element.

  2. This form submits the selected image to a Servlet.

  3. This Servlet processes the image and stores it in S3.

Anyone know of any good links/tutorials that outline sample code to perform this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌吟 2024-12-11 12:09:13

对于第三点:

  • 抓住 jets3t
  • 它的教程很简单。这是我正在使用的片段:

    S3Object fileObject = new S3Object(路径);
    fileObject.setDataInputStream(is);
    s3service.putObject(bucketName, fileObject);
    

对于前两点 - 看看这个问题

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

旧瑾黎汐 2024-12-11 12:09:13

建议您使用 html amazon API 来执行此操作。流式传输有点复杂,在大多数情况下您不需要它。

Recommend you to use html amazon API to do this. Streaming is a bit complex and in most cases you do not need it.

流绪微梦 2024-12-11 12:09:13

您还可以使用简单的表单将文件上传到 S3 存储桶。查看此示例 http://aws.amazon.com/articles/1434

示例表单:

<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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文