[Rets-dev] Photos

Bradley Matheson BMatheson at sharperagent.com
Thu Mar 8 15:17:38 CST 2007


if (webResponse.Headers[HttpResponseHeader.ContentType] == "image/jpeg")
{
    byte[] result;

    using (Stream stream = webResponse.GetResponseStream())
    {
        using (MemoryStream memoryStream = new MemoryStream())
        {
            int count = 0;
            byte[] buffer = new byte[8191];

            do
            {
                count = stream.Read(buffer, 0, buffer.Length);
                memoryStream.Write(buffer, 0, count);
            } while (count != 0);

            result = memoryStream.ToArray();
            }
    }
}

________________________________
From: rets-dev-bounces at rets.org [mailto:rets-dev-bounces at rets.org] On Behalf Of Libor Viktorin
Sent: Thursday, March 08, 2007 2:00 PM
To: Gary Miller; rets-dev at rets.org
Subject: RE: [Rets-dev] Photos

The length of the stream should be in the http header named Content-Length. In case it's missing, you may read by chunks and cumulate the result:

                MemoryStream mem = new MemoryStream();
                byte[] buffer = new byte[BUFFER_LENGTH];
                int rd;
                while((rd = strm.Read(buffer, 0, buffer.Length)) > 0) mem.Write(buffer, 0, rd);
                return mem.ToArray();

Libor

________________________________
From: Gary Miller [mailto:gary.miller at lucero.com]
Sent: Thursday, March 08, 2007 3:50 PM
To: Libor Viktorin; rets-dev at rets.org
Subject: RE: [Rets-dev] Photos

Libor and others
I'm probably missing the obvious but here is what I'm trying to do.

In C# I simply want to ready the stream into a byte array and then write the byte array to a file.  However the stream that is returned by the GetObject request doesn't support "seek" type operations so I cannot tell the length of the stream.

What am I missing?

Here is the code I'm attempting to use.

                Stream strm = getobject.ResponseStream;
                long i = strm.Length;
                byte[] a = new byte[i];
                strm.Read(a, 0, a.Length);
                FileStream fs = new FileStream(@"c:\test.jpg", FileMode.Create);
                fs.Write( a, 0, a.Length);
                fs.Close();

Gary Miller




From: Libor Viktorin [mailto:lviktorin at marketlinx.com]
Sent: Thursday, March 08, 2007 7:56 AM
To: Gary Miller; rets-dev at rets.org
Subject: RE: [Rets-dev] Photos

If you're asking about RETS 1.x, then yes.
If the request has been for only one photo (ID=entity:n, where n is not an asterisk), the body of the response is usually the jpg (or other image) file, unless there was any problem, in which case the response is usually regular xml <RETS> response with non-zero reply code.
If more than one photo has been requested, a multipart response is returned (See the specs, chapter 5.11).

Libor


________________________________
From: rets-dev-bounces at rets.org [mailto:rets-dev-bounces at rets.org] On Behalf Of Gary Miller
Sent: Wednesday, March 07, 2007 10:59 PM
To: rets-dev at rets.org
Subject: [Rets-dev] Photos

I know I'm not the first person to ask but...

Are photos returned in a byte stream from the GetObject Transaction or ?

Thanks.

Gary Miller




-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rets.org/pipermail/rets-dev/attachments/20070308/f313bc87/attachment.html


More information about the Rets-dev mailing list