简体   繁体   English

我如何理解URL中的图像是否已更改?

[英]How can I understand if Image from URL has been changed?

So, I get lots of image urls and process them into my blob storage and map it my CDN. 因此,我得到了很多图像URL,并将它们处理到我的Blob存储中,并将其映射到CDN。 Now, the problem is, sometimes images are updated in original url but url is not changed. 现在的问题是,有时图像会以原始网址进行更新,但网址没有更改。 For example: 例如:

For first image: 对于第一张图片:

Original ImageUrl: "<websiteUrl>/image1.jpg";
My BlobUrl: "<bloburl>/myimage1.jpg";
My CDN Url: "<cdnurl>/myimage1.jpg

For update image: 对于更新图像:

orignal imageurl is same, so I cannot check if image url is updated or not. 原始图片网址相同,因此我无法检查图片网址是否已更新。 I thought I could check exif datetime property but unfortunately those images does not datetime property in the exif. 我以为我可以检查exif datetime属性,但是不幸的是,这些图像在exif中没有datetime属性。 Only information I have in exif is: 我在exif中只有的信息是:

File Size 236 kB 
File Type JPEG 
MIME Type image/jpeg 
Image Width 1000 
Image Height 1500 
Encoding Process Baseline DCT, Huffman coding
Bits Per Sample 8 
Color Components 3
X Resolution 72 
Y Resolution72 
YCbCr Sub Sampling YCbCr4:2:0 (2 2)

My question is, how can I detect if image from the url is different to my image in my blob in this case. 我的问题是,在这种情况下,如何检测来自url的图像是否与我的blob中的图像不同。

In the first instance you should check the LastModified date of the file itself, that will tell you whether the file has actually changed since the last time you accessed it. 在第一种情况下,您应该检查文件本身的LastModified日期,这将告诉您自上次访问文件以来文件是否实际上已更改。 Then simply reload the file if it's newer than the date you have stored. 然后,如果文件比您存储的日期新,则只需重新加载它即可。 You could also check the size of the file, if it's not the same as it was before it's almost certainly changed. 您还可以检查文件的大小(如果它与几乎可以肯定的更改之前的大小不同)。

However, if that information isn't available to you the only way to do this is to compare the pixels of the image to see if they're different. 但是,如果您无法获得该信息,则唯一的方法是比较图像的像素以查看它们是否不同。

However, you don't have to do pixel by pixel comparison. 但是,您不必进行逐像素比较。 If you generate a checksum from the image when you first load it and store that in your database alongside the url. 如果您在第一次加载图像时从图像中生成校验和,并将其与URL一起存储在数据库中。 You can then repeat the process when you next need to display the image and compare the stored checksum against the newly calculated one. 然后,当您下次需要显示图像并将存储的校验和与新计算的校验和进行比较时,可以重复该过程。 If they are different then the images are different. 如果它们不同,则图像也不同。

It does mean that you have to retrieve the image each time whether it's been changed or not. 这确实意味着,无论是否更改了图像,您都必须每次检索图像。

You should create a checksum for your file and store that with it. 您应该为文件创建一个校验和并将其存储在其中。 Then, you can easilly calculate a new checksum to see if it has changed: 然后,您可以轻松地计算新的校验和以查看其是否已更改:

using (var md5 = MD5.Create())
{
    using (var stream = File.OpenRead(filename))
    {
        return md5.ComputeHash(stream);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何了解重点放在哪个控件上? - how can understand which control has been focused? 如何更新用户已在UI中更改的资源字符串? - How can I update a resource string that has been changed in the UI by the user? 如何识别我的网站上的唯一用户,即使IP已更改或浏览器数据已被清除? - How can I Identify unique users on my website even IP is changed or browser data has been cleared? 我如何知道.NET C#中是否更改了文件? - How can I know if a file has been changed in .NET C#? 如果在 Blazor 中更改了另一个选择框的选择,如何重置选择框的选择(设置为默认值)? - How can I reset the selection of a select box (bring to adefault value), if another select box's selection has been changed in Blazor? 我如何检查清单 <string> 已经改变了? - How can i check if a List<string> have been changed? 如何在不下载的情况下以编程方式判断网站上的二进制文件(例如图像)是否已更改? - How can I programmatically tell if a binary file on a website (e.g. image) has changed without downloading it? 如何检查DataGridViewCalendarColumn的值是否已更改? - How to check if the value of a DataGridViewCalendarColumn has been changed? 如何知道上传的文件是否已更改? - How to know if the uploaded file has been changed? 如何确定目录/文件夹是否已更改 - How to determine if a Directory/Folder has been changed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM