简体   繁体   中英

How can we download pictures of properties using librets c#?

I have tried code from here https://www.reso.org/c-sharp-photo-download-example/ but it's not working and show picture size 1KB.

Below Code I tried

 using (librets.GetObjectRequest request = new GetObjectRequest("Property", "Photo"))
                {
                    request.AddAllObjects(CurrentMLS);


                    GetObjectResponse response = session.GetObject(request);

                    foreach (ObjectDescriptor objectDescriptor in response)
                    {
                        string objectKey = objectDescriptor.GetObjectKey();
                        int objectId = objectDescriptor.GetObjectId();
                        string contentType = objectDescriptor.GetContentType();
                        string description = objectDescriptor.GetDescription();

                        Console.Write(objectKey + " object #" + objectId);
                        if (description.Length != 0)
                            Console.Write(", desription: " + description);
                        Console.WriteLine();

                        string outputFileName = photoFilePath+"\\"+objectKey + "-" + objectId + ".jpg";

                        Stream outputStream = File.OpenWrite(outputFileName);
                       
                            const int BUFFER_SIZE = 1024;
                            Stream stream = objectDescriptor.GetDataStream();
                            byte[] buffer = new Byte[BUFFER_SIZE];
                            int bytesRead;
                            while ((bytesRead = stream.Read(buffer, 0, BUFFER_SIZE)) > 0)
                            {
                                outputStream.Write(buffer, 0, bytesRead);
                            }
                       
                        outputStream.Close();
                    }

                }

It doesn't look like you're filtering by contentType. If you trust the RETS server to send properly formatted content type strings, then you could filter the objects down to JPEGs only using something like this:

            string contentType = objectDescriptor.GetContentType();

            // skip objects that don't appear to be JPEGs
            if (contentType != "image/jpeg") { continue; };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM