Когда пользователь добавляет изображение, я загружаю его в хранилище BLOB-объектов Azure с помощью конкретное имя (из 3 переменных).
Но если пользователь удалит и добавит одно из этих изображений, изображение останется прежним из-за кеша и потому, что я сохраняю то же имя. Я не хочу менять имя файла, чтобы избежать управления удалением в хранилище BLOB-объектов Azure.
Вот код метода загрузки:
Код: Выделить всё
public async Task UploadFileToCloudAsync(string containerName, string name, Stream file)
{
var cloudBlobContainerClient = await StorageHelper.ConnectToBlobStorageAsync(_blobStorageEndPoint, containerName);
if (cloudBlobContainerClient == null)
{
throw new NullReferenceException($"Unable to connect to blob storage {name}");
}
BlobClient blobClient = cloudBlobContainerClient.GetBlobClient(name);
await blobClient.UploadAsync(file, true);
var headers = await CreateHeadersIfNeededAsync(blobClient);
if (headers != null)
{
// Set the blob's properties.
await blobClient.SetHttpHeadersAsync(headers);
}
return blobClient.Uri.AbsoluteUri;
}
Код: Выделить всё
private readonly string _defaultCacheControl = "max-age=3600, must-revalidate";
private async Task CreateHeadersIfNeededAsync(BlobClient blobClient)
{
BlobProperties properties = await blobClient.GetPropertiesAsync();
BlobHttpHeaders headers = null;
if (properties.CacheControl != _defaultCacheControl)
{
headers = new BlobHttpHeaders
{
// Set the MIME ContentType every time the properties
// are updated or the field will be cleared
ContentType = properties.ContentType,
ContentLanguage = properties.ContentLanguage,
CacheControl = _defaultCacheControl,
ContentDisposition = properties.ContentDisposition,
ContentEncoding = properties.ContentEncoding,
ContentHash = properties.ContentHash
};
}
return headers;
}
Подробнее здесь: https://stackoverflow.com/questions/668 ... name-image