2

I am working on this problem and the proposed solution works for me.

However, now I need to make this work in my actual application which is an AWS Beanstalk .NET web application. My beanstalk application knows the url source of the picture. Knowing the url, I can get a stream and process the file (by creating a byte array and even a Bitmap object).

However, it seems that to get the file properties as mentioned above (such as the camera type or painting application that created the file), I really need a local file because that is the expected input argument.

This is a problem for me. I know the http link, I know the bytes but I have no such thing as a file path.

How can I solve this? I need the windows file properties.

Daan
  • 2,478
  • 3
  • 36
  • 76
  • Have you download the file and check if that after downloading you get the properties? This is just to make sure the properties are extractable from a download file. Then next part would be to figure out how to do it without a download – Tarun Lalwani May 21 '18 at 19:37
  • Yes, now I need to find out how to do it without saving the file – Daan May 21 '18 at 19:39
  • Can you add a sample URL to the question of such a file and the expected extracted data? – Tarun Lalwani May 21 '18 at 19:40
  • The pictures I work with are confidential. But you can take a picture with your phone. When saving the picture to your file system, the company name of the phone is mentioned in these properties. – Daan May 21 '18 at 19:43
  • I think what you are looking for is EXIF data. http://www.exif.org/Exif2-2.PDF. I doubt you would get a library which is extracting data from a online file without downloading it completely. What you will have to do is understand what is the minimum bytes you need to get to extract EXIF info, download those bytes and extract the information. Not going to be easy as you would need a deepdive into the same. This python code may show some logic of what needs to be done https://github.com/python-pillow/Pillow/blob/81c88b1ead5343d9778a82977c9c6c1150fd9738/src/PIL/JpegImagePlugin.py – Tarun Lalwani May 21 '18 at 20:05
  • Thanks. But I am afraid to admit I am not smart enough for these low level things. I need a clear example on how to do this for C# – Daan May 21 '18 at 20:08
  • You should wait and see if someone has something you can use in C#, also do read https://stackoverflow.com/questions/13861581/get-exif-data-without-downloading-whole-image-python – Tarun Lalwani May 21 '18 at 20:22
  • This nuget https://drewnoakes.com/code/exif/ can read exif from a Stream (MetadataExtractor.ReadMetadata) if you're only after images. – Simon Mourier May 22 '18 at 04:54

1 Answers1

1

If I understood you correctly, you want to read image metadata from a URL without saving it to a file first, i.e. directly from the Internet.

Here is one way that works for me:

string demoImageUrl = "https://raw.githubusercontent.com/ianare/exif-samples/master/jpg/Canon_40D.jpg";

byte[] imgData = null;

using (var wc = new WebClient())
{
    imgData = wc.DownloadData(demoImageUrl);
}

using (var sr = new MemoryStream(imgData, false))
{
    BitmapSource image = BitmapFrame.Create(sr);
    BitmapMetadata md = (BitmapMetadata)image.Metadata;
    string comment = md.Comment;
    string title = md.Title;
    string dateTaken = md.DateTaken;
}

You need to add references to PresentationCore and WindowsBase assemblies and also include the following namespace:

using System.Windows.Media.Imaging;

Result

Isma
  • 14,604
  • 5
  • 37
  • 51