【问题标题】:set CORS for AWS Presign URL and set cacheControl for S3 files?为 AWS Presign URL 设置 CORS 并为 S3 文件设置 cacheControl?
【发布时间】:2021-10-21 06:47:47
【问题描述】:

我是 AWS 新手,我有 2 个问题:

  1. 我使用 Presign URL 为视频生成 URL,它工作正常。但是当我将视频 URL 放到其他网站时,它可以正常显示。我希望它只在我的域上服务。我这样设置 CORS 配置,但它不支持 Presign URL,它仅适用于图像和其他类型。

这样的存储桶设置

  1. 我将文件从其他网站传输到 S3,我需要为每个文件设置缓存控制元。我有如下代码,但它不起作用。有什么方法可以设置一条适用于所有上传到 S3 的文件的规则,它会自动更新元数据?

    // 将视频传输到 S3 export const transferVideoToS3 = (videoUrl, 文件名, 回调) => { 要求({ 网址:视频网址, 编码:空 },函数(错误,res,正文){ if (err) 返回回调(err, res);

         s3.upload({
             Bucket: 'myvideos',
             Key: `public/videos/${filename}.mp4`,
             cacheControl: 'max-age=604800',
             ContentType: res.headers['content-type'],
             ContentLength: res.headers['content-length'],
             Body: body // buffer
         }, callback)
     })
    

    }

感谢您的帮助

【问题讨论】:

    标签: javascript node.js amazon-s3


    【解决方案1】:

    我猜可以通过以下设置实现

    GeneratePresignedUrlRequest generatePresignedUrlRequest = new GeneratePresignedUrlRequest(bucketName, path)
    .withMethod(HttpMethod.PUT).withExpiration(expiration);
    
    generatePresignedUrlRequest.addRequestParameter("cache-control","max-age=604800,public");
    

    【讨论】:

      猜你喜欢
      • 2017-12-16
      • 1970-01-01
      • 2017-10-16
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多