我可以通过AWS API-GATEWAY将Form-DATA文件上传到S3吗?

发布于 2025-02-08 19:56:09 字数 160 浏览 3 评论 0 原文

在AWS环境中,我想通过API网关将文件上传到S3。我不能使用lambda,因为6MB有效载荷限制。 (API网关的10MB限制很好。)我可以设法上传使用Post请求和二进制主体的文件。我的问题是如何上传包裹在多部分/form-data中的图片,可以在不使用lambda函数的情况下设置文件大小和格式限制?

In AWS environment I want to upload a file to S3 via API gateway. I can't use lambda, because the 6MB payload limit. (The API gateway's 10MB limit is fine.) I could manage to upload a file with POST request and binary body. My question is how can I upload a picture which is wrapped in a multipart/form-data and can I set a file size and format limitation without using lambda functions?

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

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

发布评论

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

评论(1

甜点 2025-02-15 19:56:09

您应该使用AWS-SDK创建API终点并获取URL:

  • api代码(aws-sdk api doc)

    • 用于上传,参考 s3.getSignedurl('putobject')
    • 不要使用 s3.putobject 用于上传文档,这是一个差异概念
    • 示例:
       返回新的Promise(((解决,拒绝)=> {
        令url = this.s3.getSignedUrl(“ getObject”,{
        水桶:水桶,
        钥匙:钥匙,
        到期:Expires_second
      }))
      返回分辨率(URL)
       
  • s3 bucket config (参考链接)

    • 选择您的存储桶
    • 权限选项卡>跨原生资源共享(CORS)>编辑
        [
          {
            “允许的人”:[
              “*”,
              “授权”
            ],,
            “允许的方法”:[
              “邮政”,
              “得到”,
              “放”,
              “删除”,
              “头”
            ],,
            “允许的人”:[
              “*”
            ],,
            “ ExposeHeaders”:[],
            “ MaxageseConds”:3000
          }  
        这是给出的
       
    • 确认您的允许的方法现有 put 方法
  • 上传文档(Postman Case)

    • 复制并粘贴从 s3.getSignedurl('putobject')
    • 获得的链接

    • 身体选项卡>二进制选择您的文档
    • 标题>取消选中“ content-type”,“用户代理”
    • [可选]如果您想接受选定的文件类型,请编辑 {coct:'*/*'}
      • 示例: {Accept:'Image/png'}
    • put 方法发送
  • 发送,现在您可以检查S3桶

其他有用的参考

You should use aws-sdk to create the API end point and get the url:

  • API Code (aws-sdk API Doc):

    • for upload, reference s3.getSignedUrl('putObject')
    • Don't use S3.putObject for upload document, it is a difference concept
    • Example:
      return new Promise((resolve, reject) => {
        let url = this.S3.getSignedUrl("getObject", {
        Bucket: bucket,
        Key: key,
        Expires: expires_second
      })
      return resolve(url)
      
  • S3 Bucket Config (Reference Link):

    • Select your bucket
    • Permissions Tab > Cross-origin resource sharing (CORS) > Edit
        [
          {
            "AllowedHeaders": [
              "*",
              "Authorization"
            ],
            "AllowedMethods": [
              "POST",
              "GET",
              "PUT",
              "DELETE",
              "HEAD"
            ],
            "AllowedOrigins": [
              "*"
            ],
            "ExposeHeaders": [],
            "MaxAgeSeconds": 3000
          }  
        ]
      
    • Confirm your AllowedMethods existing PUT method
  • Upload Document(Postman case)

    • Copy and paste the link which get from s3.getSignedUrl('putObject')
    • Body tab > binary > select you document
    • Headers > uncheck 'Content-Type', 'User-Agent'
    • [Optional] if u want to accept selected file type, edit { Accept: '*/*'}
      • Example: {Accept: 'image/png' }
    • Send with PUT method
  • now you may check the s3 bucket

other helpful reference:
https://medium.com/@aidan.hallett/securing-aws-s3-uploads-using-presigned-urls-aa821c13ae8d

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