使用CloudFront的无效路径在C#中创建无效 [英] Invalid paths using CloudFront create invalidation in C#

查看:43
本文介绍了使用CloudFront的无效路径在C#中创建无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使C#/.NET中的CloudFront对象无效并获取以下异常:

I am trying to invalidate CloudFront objects in C#/.NET and gettign the following exception:

您的请求包含一个或多个无效的无效路径.

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,如下所示:

The array passed to the function contains a single Url like so:

images/temp_image.jpg

该图像存在于S3存储桶中,并已在CloudFront URL中的浏览器中加载.

The image exists in the S3 bucket and loaded in the browser in the CloudFront URL.

我在做什么错了?

推荐答案

当您向CloudFront中的某个对象发送无效请求时,即使无效完成,您仍可以在浏览器中的CloudFront URL中看到您的图片,因为无效不会从S3存储桶中删除对象,并在浏览器中向该图像发出新请求,CloudFront再次将这些URl缓存到边缘位置中的images/temp_image.jpg中.

When you send invalidation request to some object in CloudFront, you still can see your picture in the browser in the CloudFront URL even when invalidation completed, because invalidation does not delete object from S3 bucket and with new request to this image from you browser CloudFront again cached these URl to images/temp_image.jpg in edge locations.

当您更新具有相同名称的图像时,将看到对象无效.

Invalidation of object will be seen, when you update image with the same name.

您的失效功能是正确的.

Your Invalidation function is correct.

这篇关于使用CloudFront的无效路径在C#中创建无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆