代码之家  ›  专栏  ›  技术社区  ›  user1464139

如何在S3和Cloudfront Distributions中使用Write-S3Object设置缓存控制?

  •  6
  • user1464139  · 技术社区  · 10 年前

    我一直这样做,但现在似乎不再奏效了(2015年8月):

    Write-S3Object -BucketName "example-bucket" 
       -KeyPrefix "app/admin/partials" 
       -Folder 'app/admin/partials' -SearchPattern '*.html' 
       -HeaderCollection @{"Cache-Control" = "public,max-age=120"}
    

    最近有什么变化吗?当我在S3中检查时,没有设置标题信息。

    2 回复  |  直到 10 年前
        1
  •  0
  •   DanH    10 年前

    您需要使用 -元数据 参数,更改 -HeaderCollection @{"Cache-Control" = "public,max-age=120"} 参数到 -Metadata @{"Cache-Control" = "public,max-age=120"} 工作正常,可以在AWS web控制台中看到。

    这是工作片段

     Write-S3Object -BucketName myBucket -file "test.json" -Metadata
     @{"Cache-Control" = "public,max-age=120"}
    

    这是使用以下版本的Powershell运行的。

    PS C:\Users\DanielH1> Get-AWSPowerShellVersion
    
    AWS Tools for Windows PowerShell
    Version 3.1.5.1
    Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
    
    Amazon Web Services SDK for .NET
    Version 3.1.0.2
    Copyright 2009-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
    
    Release notes: https://aws.amazon.com/releasenotes/PowerShell
    
    This software includes third party software subject to the following copyrights:
    - Logging from log4net, Apache License
    [http://logging.apache.org/log4net/license.html]
    

    以下是参考文档的链接: http://docs.aws.amazon.com/powershell/latest/reference/items/Write-S3Object.html

        2
  •  0
  •   Raphael Isidro    9 年前

    发生在我身上的是 页眉集合 上传单曲时效果很好 文件 但在上载 文件夹 .

    事实证明 元数据 与一起工作 文件夹 尽管你最终得到了两个标题,在我的例子中:

    Cache-Control max-age=9999
    x-amz-meta-cache-control max-age=9999
    

    让事情变得更糟 元数据 有一张单人床 文件 不起作用

    因此,我决定在@params变量中添加两个参数(HeaderCollection和Metadata),并让脚本将两个头放在所有文件上。

    希望它能帮助某人:)