Jump to content
Michel Bernabela

Datasnap server updating error image blob column

Recommended Posts

Hello,

I am busy with for quite awhile now with an issue with no results. I have looked many internet sites, but without any luck at all.
>
> I am trying to insert/update (text/image) data via a Client to a Datasnap Server by using FDQuery and ExecSQL (XE7 with Interbase 2017).
>
> If I only make the use of text, insertion and/or updation works fine and perfect without any problems.
> But as soon as I add an extra image parameter as Stream, the following error message is produced:
>
> "HTTP/1.1 500 Internal Server Error"
>
> But the record INCLUDING the image stream is inserted into the remote Datasnap database, but my client application afterwards crashes and produces another access violation error upon closing the client app.
>
> So everything works fine/perfect with text only, WITHOUT image (stream) param.
>
> My server method uses FDQuery component for the insert (and one for update not included in this example)):
>
> // Push punch data to HQ
> Function TdmServerMethod.iApp_PushPunch(FPdtFrom, FPdtDateIn, FPmsPic: TMemoryStream): Boolean;
> Begin
>    Result := True; // Init
>    With qryPushPunch Do Begin //FDQuery component
>      Try
>        FPmsPic.Position := 0; // FPmsPic.Seek(0, soFromBeginning); Return cursor of stream to the beginning
>        Close; // Make sure dataset is not active
>        ParamByName('EP_FROM').AsDate         := FPdtFrom;
>        ParamByName('TS_DATEIN').AsDate       := FPdtDateIn;
>        ParamByName('TS_PICIN').AsStream      := FPmsPic;                           THIS LINE WILL CAUSE/PRODUCE THE ERROR
>        ParamByName('TS_PICIN').LoadFromStream(FPmsPic, ftBlob);           THIS LINE WILL CAUSE/PRODUCE THE ERROR
>        ExecSQL(); // Execute SQL statement
>        CloseStreams; // Cleanup stream
>        Close; // Cleanup dataset
>      Except
>        Result := False;
>      End;
>    End;
> End;
>
> My Client REST method is as follow:
>
> Function TdmServerMethodClient.iApp_PushPunch(FPdtFrom: TDateTime; FPdtDateIn: TDateTime; FPmsPic: TMemoryStream; Const ARequestFilter: String): Boolean;
> Begin
>    If FiApp_PushPunchCommand = Nil Then Begin
>       FiApp_PushPunchCommand := FConnection.CreateCommand;
>       FiApp_PushPunchCommand.RequestType := 'POST';
>       FiApp_PushPunchCommand.Text := 'TdmServerMethod."iApp_PushPunch"';
>       FiApp_PushPunchCommand.Prepare(TdmServerMethod_iApp_PushPunch);
>    End;
>    FiApp_PushPunchCommand.Parameters[0].Value.AsDateTime := FPdtFrom;
>    FiApp_PushPunchCommand.Parameters[1].Value.AsDateTime := FPdtDateIn;
>    FiApp_PushPunchCommand.Parameters[10].Value.SetStream(FPmsPic, FInstanceOwner);
>    FiApp_PushPunchCommand.Execute(ARequestFilter); AFTER EXECUTION THE ERROR "HTTP/1.1 500 INTERNAL ERROR" IS TRIGGERED, BUT THE RECORD INCLUDING THE IMAGE IS PERFECTLY INSERTED/UPDATED IN DE DATABASE
>    Result := FiApp_PushPunchCommand.Parameters[11].Value.GetBoolean;
> End;
 

Edited by Michel Bernabela

Share this post


Link to post
Guest

I'd start by removing the "with" and then debug. Keep tracing after iApp_PushPunch.

 

HTH,

 

/D

Share this post


Link to post

Hi Dany,

 

Many thnx for your reply.

After debugging the error arises in my REST client method on executing the command:

 

>    FiApp_PushPunchCommand.Execute(ARequestFilter);

 

In the IdHTTP pas file it raises the error on the stream...

Edited by Michel Bernabela

Share this post


Link to post
Guest

deleted

Edited by Guest
To fast...

Share this post


Link to post
On 8/4/2019 at 1:23 PM, Michel Bernabela said:

>    FiApp_PushPunchCommand.Parameters[0].Value.AsDateTime := FPdtFrom;
>    FiApp_PushPunchCommand.Parameters[1].Value.AsDateTime := FPdtDateIn;
>    FiApp_PushPunchCommand.Parameters[10].Value.SetStream(FPmsPic, FInstanceOwner);

Is there a particular reason that the params are numbered 0, 1, 10 ?

 

On the server side - have you inspected the stream after you fill it from the request?  Does the length of the stream match the size of the image?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×