Google cloud platform 替换Google云存储中的对象,然后云CDN花时间刷新缓存
我已启用谷歌云存储版本,以替换相同名称的图像,如,但在3-4分钟后刷新或有时不刷新。我正在使用.net core管理替换,但没有获得解决方案。问题是用户可以随时上传同名图片。这是我的密码Google cloud platform 替换Google云存储中的对象,然后云CDN花时间刷新缓存,google-cloud-platform,google-cloud-storage,google-cloud-cdn,Google Cloud Platform,Google Cloud Storage,Google Cloud Cdn,我已启用谷歌云存储版本,以替换相同名称的图像,如,但在3-4分钟后刷新或有时不刷新。我正在使用.net core管理替换,但没有获得解决方案。问题是用户可以随时上传同名图片。这是我的密码 public virtual void UploadGoogle(string localPath, string location, string contentType) { try { bool cdnStatus = Convert.T
public virtual void UploadGoogle(string localPath, string location, string contentType)
{
try
{
bool cdnStatus = Convert.ToBoolean(_configuration.GetSection("AppSetting")["GoogleCdnStatus"]);
if (cdnStatus)
{
var gcpPath = _configuration.GetSection("GoogleCloudStorage")["fileName"];
var gcpCredential = Path.Combine(_hostingEnvironment.ContentRootPath, gcpPath);
var gCPStorageCredential = GoogleCredential.FromFile(gcpCredential);
// Instantiates a client.
using (StorageClient storageClient = StorageClient.Create(gCPStorageCredential))
{
// The name for the new bucket.
string bucketName = _configuration.GetSection("AppSetting")["Googlebucket"];
using (var f = System.IO.File.OpenRead(localPath))
{
//objectName = objectName ?? Path.GetFileName(localPath);
//UploadObjectOptions uploadObjectOptions = new UploadObjectOptions();
//uploadObjectOptions.
//if (localPath.Contains("Profile"))
//{
// //storageClient.DeleteObject(bucketName, location);
// try
// {
// Bucket bucket = new Bucket();
// bucket = storageClient.GetBucket(bucketName);
// Bucket.VersioningData versioningData = new Bucket.VersioningData();
// versioningData.Enabled = true;
// bucket.Versioning = versioningData;
// storageClient.UpdateBucket(bucket);
// }
// catch (Exception ex)
// {
// }
// storageClient.UploadObject(bucketName, location, contentType, f);
//}
//else
//{
// storageClient.UploadObject(bucketName, location, contentType, f);
//}
Bucket bucket = new Bucket();
bucket = storageClient.GetBucket(bucketName);
Bucket.VersioningData versioningData = new Bucket.VersioningData();
versioningData.Enabled = false;
bucket.Versioning = versioningData;
storageClient.UpdateBucket(bucket);
storageClient.UploadObject(bucketName, location, contentType, f);
}
//try
//{
// // Creates the new bucket.
// storageClient.CreateBucket(projectId, bucketName);
// Console.WriteLine($"Bucket {bucketName} created.");
//}
//catch (Google.GoogleApiException e)
//when (e.Error.Code == 409)
//{
// // The bucket already exists. That's fine.
// Console.WriteLine(e.Error.Message);
//}
}
}
}
catch (Exception ex)
{
}
}
我试图删除对象并再次上传,但同样的事情发生了。我和谷歌的支持人员谈过,但他们并没有给出想法,实际上为什么会发生这种情况,因为他们只是说他们在编程方面帮不了忙。如果您在代码中看到,我尝试了版本启用或禁用这两种情况