Article View: borland.public.cppbuilder.internet.web
Article #1326Re: Active Server Object PART 2
From: Remy Lebeau (TeamB)
Date: Thu, 24 Mar 2005 19:48
Date: Thu, 24 Mar 2005 19:48
80 lines
3407 bytes
3407 bytes
"melk" <NOSPAMi_melk@libero.it> wrote in message
news:4242c7fd@newsgroups.borland.com...
> I have to write out to the ASP page directly a JPEG byte array,
There are several steps you have to do in order for that to work.
1) prepare a VARIANT that contains a SAFEARRAY that contains the raw bytes
2) set the IResponse::ContentType property to "image/jpeg".
3) call IResponse::AddHeader() to add an additional "Content-Length" header
value.
4) pass the VARIANT to IResponse::BinaryWrite().
> first I tried to looking for a Method of IRepsonse Interface
"ContentStream"
> that I saw use in Delphi code but i can't find it in BC++ 6...
There is no such property/method in IResponse. The Delphi code must have
been using something else.
> this method accept a Stream type like one that exit from
TJPEGImage::SaveToStream..
You are probably looking at code realted to the Indy library
(http://www.indyproject.org). That has nothing to do with ASP programming.
> finaly I tried to use IResponse::binaryWrite without effect, it
> doesn't write on the page..
BinaryWrite() is what you need to use. You probably just did not set it up
properly. Try the following code:
#include <memory>
{
Response->Clear();
Response->put_Buffer(VARIANT_TRUE);
try
{
std::auto_ptr<TMemoryStream> MemStream(new TMemoryStream);
JPEGImage->SaveToStream(MemStream.get());
SAFEARRRAYBOUND bounds = {0, MemStream->Size-1};
TVariant v;
v.parray = ::SafeArrayCreate(VT_UI1, 1, &bounds);
v.vt = VT_ARRAY|VT_UI1;
if( v.parray == NULL )
throw Exception("Cannot create the array of bytes");
void *data = NULL;
if( FAILED(::SafeArrayAccessData(v.parray, &data)) )
throw Exception("Cannot access the array of bytes");
memcpy(data, MemStream->Memory, MemStream->Size);
::SafeArrayUnaccessData(v.parray);
Response->put_Status(WideString("200 OK"));
Response->put_ContentType(WideString("image/jpeg"));
Response->AddHeader(WideString("Content-Length"),
WideString(IntToStr(MemStream->Size)));
Response->BinaryWrite(v);
}
catch(const Exception &e)
{
Response->Clear();
Response->put_Status(WideString("500 " + e.Message));
}
Response->Flush();
}
Gambit
Technical Details
Message-ID:
<42431956$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<4242c7fd@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: feeec,1b87c7406bae033 X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.web References: <4242c7fd@newsgroups.borland.com> Subject: Re: Active Server Object PART 2 Date: Thu, 24 Mar 2005 11:48:42 -0800 Lines: 82 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <42431956$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1111693654 68.69.17.41 (24 Mar 2005 11:47:34 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.maxwell.syr.edu!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail