Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Looking for alternative to Response.ContentStream access in IW 14.0.39


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Apr 27, 2015 3:30 AM Last Post By: Alexandre Machado
Henrik Spranz

Posts: 3
Registered: 3/10/11
Looking for alternative to Response.ContentStream access in IW 14.0.39  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 20, 2015 3:26 AM
Hi!

I know the ‘contentstream already exists’ error was already handled in a thread, but this doesn’t help me in my case.

I have to migrate a Delphi/Intraweb/ExtJS application from Intraweb 10 to Intraweb 14 and got source access.

I use several Callback routines on the server to get grid data, images and other resources.

Here’s an example for sending grid data to the browser in an async callback in IW 10:
//------------------------------------------------------------------------------
procedure TExtJSGrid.DoOnAsyncRead(AParams: TStringList; AApplication: TIWApplication);
var lJSONString  : String;
begin
  AApplication.Response.ContentType := AnsiString('application/json; charset=utf-8');
  lJSONString := GetDataString(AParams);
  AApplication.Response.ContentStream := TStringStream.Create(UTF8Encode(lJSONString));
end;


or here an example to send images back to the browser in a callback (just the important part):
    if FileExists(sValue) then begin
      cStream.LoadFromFile(sValue);
    end;
    sExt := ExtractFileExt(sValue);
    if SameText(sExt, '.img') then begin
      aApplication.Response.ContentType := 'image';
    end
    else begin
      aApplication.Response.ContentType := AnsiString(GetContentType(sExt));
    end;
 
    aApplication.Response.ContentStream := cStream;
    aApplication.Response.LastModified := Now;
    aApplication.Response.Expires := IncDay(Now, 1);

This has worked like a charm in IW 10 and in IW 14 there’s no access anymore to aApplication.Response.ContentStream and if we use SendStream, SendFile or SetRenderOverride like you propose we got either ‘contentstream already exists’, ‘responsetype already set’ or the client expects JSON data (‘Ext.JSON.decode(): You're trying to decode an invalid JSON String’).

How can we achieve what was so easy in Intraweb 10?

Regards,
Henrik
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Looking for alternative to Response.ContentStream access in IW 14.0.39  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 27, 2015 3:30 AM   in response to: Henrik Spranz in response to: Henrik Spranz
Henrik Spranz wrote:
Hi!

I know the ‘contentstream already exists’ error was already handled in a thread, but this doesn’t help me in my case.

I have to migrate a Delphi/Intraweb/ExtJS application from Intraweb 10 to Intraweb 14 and got source access.

I use several Callback routines on the server to get grid data, images and other resources.

Here’s an example for sending grid data to the browser in an async callback in IW 10:
//------------------------------------------------------------------------------
procedure TExtJSGrid.DoOnAsyncRead(AParams: TStringList; AApplication: TIWApplication);
var lJSONString  : String;
begin
  AApplication.Response.ContentType := AnsiString('application/json; charset=utf-8');
  lJSONString := GetDataString(AParams);
  AApplication.Response.ContentStream := TStringStream.Create(UTF8Encode(lJSONString));
end;


or here an example to send images back to the browser in a callback (just the important part):
    if FileExists(sValue) then begin
      cStream.LoadFromFile(sValue);
    end;
    sExt := ExtractFileExt(sValue);
    if SameText(sExt, '.img') then begin
      aApplication.Response.ContentType := 'image';
    end
    else begin
      aApplication.Response.ContentType := AnsiString(GetContentType(sExt));
    end;
 
    aApplication.Response.ContentStream := cStream;
    aApplication.Response.LastModified := Now;
    aApplication.Response.Expires := IncDay(Now, 1);

This has worked like a charm in IW 10 and in IW 14 there’s no access anymore to aApplication.Response.ContentStream and if we use SendStream, SendFile or SetRenderOverride like you propose we got either ‘contentstream already exists’, ‘responsetype already set’ or the client expects JSON data (‘Ext.JSON.decode(): You're trying to decode an invalid JSON String’).

Can you send us a sample application showing the problem? It is almost impossible to reproduce the problem with just this piece of code...
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02