In google, images are hosted in CDN URL type and I tried to download as an image from that CDN but it throws an error in C#. Used this c# code attached below.
using (var webClient = new WebClient())
{
byte[] imageBytes = webClient.DownloadData(imageUUl);
System.IO.File.WriteAllBytes(@"E:\Temp\img2.jpeg", imageBytes);
}
Thanks in advance.
In GCP Cloud CDN, you can use a signed URL with authentication or signed cookies to authorize users and provide them with a time-limited token for accessing your protected content, so a Cloud CDN does not block requests without a signature query parameter or Cloud-CDN-Cookie HTTP cookie. It rejects requests with invalid (or otherwise malformed) request parameters, due to this I suggest reviewing your browser client security settings; how the authentication is managed to your CDN URL. Some clients store cookies by default if the security policy is allowed, also review how your CDN URL security ingress is configured because when you are using a CDN URLs with signed cookies the responses to signed and unsigned requests are cached separately, so a successful response to a valid signed request is never used to serve an unsigned request. In another hand if you are using a signed CDN URL to limited secure access to file for a limited amount of time, there are some steps that you need to follow first:
Ensure that Cloud CDN is enabled.
If necessary, update to the latest version of the Google Cloud CLI:
Creating keys for your signed URLs
To create keys, follow these steps.
Configuring Cloud Storage permissions.
Before you run the following command, add at least one key to a backend bucket in your project; otherwise, the command fails with an error because the Cloud CDN cache fill service account is not created until you add one or more keys for the project. Replace PROJECT_NUM with your project number and BUCKET with your storage bucket.
gsutil iam ch \ serviceAccount:[email protected]:objectViewer \ gs://BUCKETList the keys on a backend service or backend bucket, run one of the following commands:
gcloud compute backend-services describe BACKEND_NAMEgcloud compute backend-buckets describe BACKEND_NAMESign URLs and distribute them.
You can sign URLs by using the
gcloud compute sign-urlcommand or by using code that you write yourself. If you need many signed URLs, custom code provides better performance. This command reads and decodes the base64url encoded key value fromKEY_FILE_NAME, and then outputs a signed URL that you can use for GET or HEAD requests for the given URL.In this link, you can find more info related to signed URLs and signed cookies.