我正在尝试使 C#/.NET 中的 CloudFront 对象无效并引发以下异常:
Your request contains one or more invalid invalidation paths.
我的函数:
public bool InvalidateFiles(string[] arrayofpaths)
{
for (int i = 0; i < arrayofpaths.Length; i++)
{
arrayofpaths[i] = Uri.EscapeUriString(arrayofpaths[i]);
}
try
{
Amazon.CloudFront.AmazonCloudFrontClient oClient = new Amazon.CloudFront.AmazonCloudFrontClient(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, Amazon.RegionEndpoint.USEast1);
CreateInvalidationRequest oRequest = new CreateInvalidationRequest();
oRequest.DistributionId = ConfigurationManager.AppSettings["CloudFrontDistributionId"];
oRequest.InvalidationBatch = new InvalidationBatch
{
CallerReference = DateTime.Now.Ticks.ToString(),
Paths = new Paths
{
Items = arrayofpaths.ToList<string>(),
Quantity = arrayofpaths.Length
}
};
CreateInvalidationResponse oResponse = oClient.CreateInvalidation(oRequest);
oClient.Dispose();
}
catch
{
return false;
}
return true;
}
传递给函数的数组包含单个 Url,如下所示:
images/temp_image.jpg
图像存在于 S3 存储桶中,并通过 CloudFront URL 在浏览器中加载。
我做错了什么?
最佳答案
您的无效文件路径需要在字符串的前面有一个/。
如果您有疑问,可以登录 AWS Management,转到 Cloudfront,选择您尝试使文件失效的分配,选择分配设置并转到无效选项卡。
然后您可以手动创建验证,这允许您检查您的路径是否正确。
关于c# - 使用 CloudFront 的无效路径在 C# 中创建失效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25382449/