Watch, Follow, &
Connect with Us

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


Welcome, Guest
Guest Settings
Help

Thread: Files list in THttpRequest is empty when called from indy client


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


Permlink Replies: 5 - Last Post: Jun 17, 2016 2:51 AM Last Post By: Alexandre Machado
Paul Richardson

Posts: 10
Registered: 2/3/08
Files list in THttpRequest is empty when called from indy client  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 10, 2016 9:00 AM
Hello
I'm trying to migrate from D2007 IW9 to Delphi 10.1 Berlin and IW14 however I'm having some issues with file uploads. I'm trying to make a call to the Intraweb server using an delphi client using Indy's components namely a TIdHTTP and a TIdMultiPartFormDataStream. I add a form field and a file to the TIdMultiPartFormDataStream then post them to the Intraweb server using a Post call from a TIdHTTP component.
The client code is :
procedure TForm2.Button1Click(Sender: TObject);
var
    p_sendstream : TIdMultiPartFormDataStream;
    p_img : TFileStream;
    p_reply : String;
    p_imgname : TIdHTTP;
begin
      p_sendstream := TIdMultiPartFormDataStream.Create;
      p_sendstream.AddFormField('test.jpg','image1');
      p_imgname := TIdHTTP.Create(nil);
      p_sendstream.AddFile(
        'File1',
        'd:\AD_Test.jpg','image/jpeg');
 
        P_reply := p_imgname.Post('http://127.0.0.1:8081/:upload', p_sendstream);
        if (p_imgname.Connected) then
          p_imgname.Disconnect;
end;

When I breakpoint the server on the BeforeDispatch event then the Request parameter has no files or ContentFields.
If I point the same client at an Intraweb server created in D2007 then all is fine and the files / content fields can be accessed without issue.

Does anyone know what I've missed or need to change to access the files so that the multipartformdata is passed through the request properly?

Thanks

Paul
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Files list in THttpRequest is empty when called from indy client  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 10, 2016 10:00 AM   in response to: Paul Richardson in response to: Paul Richardson
Paul wrote:

p_sendstream.AddFormField('test.jpg','image1');

That does not look right. Do you maybe have your parameter values in the
wrong order? The first parameter is the field name, the second parameter
is the field value. Is your server really expecting a field named 'test.jpg'
with a value of 'image1'? Or is it actually expecting a field named 'image1'
with a value of 'test.jpg'?

P_reply := p_imgname.Post('http://127.0.0.1:8081/:upload', p_sendstream);

Why is there a ':' in '/:upload'?

if (p_imgname.Connected) then
p_imgname.Disconnect;

You don't need that at all.

--
Remy Lebeau (TeamB)
Paul Richardson

Posts: 10
Registered: 2/3/08
Re: Files list in THttpRequest is empty when called from indy client  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 13, 2016 1:42 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy,
Thank you very much for your reply. In answer to your questions, the order of the parameters doesn't make any difference. I'm break pointing the server and there are no parameter or files in the THttpRequest that is passed to the OnExecuteRequest event. This is the reason I've asked this question as it works fine in old versions of IW but something appears to have changed / broken in more recent versions and I can't seem to work out what.

The :'s well I don't honestly know, this project was initially written back when D2007 had just come out and I had just started out as a trainee programmer. Now I don't really want to re-write the client and server to remove them all.

Will remove the disconnect line in future - thanks for the advice.

Paul

Remy Lebeau (TeamB) wrote:
Paul wrote:

p_sendstream.AddFormField('test.jpg','image1');

That does not look right. Do you maybe have your parameter values in the
wrong order? The first parameter is the field name, the second parameter
is the field value. Is your server really expecting a field named 'test.jpg'
with a value of 'image1'? Or is it actually expecting a field named 'image1'
with a value of 'test.jpg'?

P_reply := p_imgname.Post('http://127.0.0.1:8081/:upload', p_sendstream);

Why is there a ':' in '/:upload'?

if (p_imgname.Connected) then
p_imgname.Disconnect;

You don't need that at all.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Files list in THttpRequest is empty when called from indy client  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 13, 2016 1:14 PM   in response to: Paul Richardson in response to: Paul Richardson
Paul wrote:

the order of the parameters doesn't make any difference.

Yes, it does. AddFormField('test.jpg','image1') produces this POST data:

--boundary
Content-Disposition: form-data; name="test.jpg"
 
image1


Whereas AddFormField('image1','test.jpg') produces this POST data instead:

--boundary
Content-Disposition: form-data; name="image1"
 
test.jpg


That makes a BIG difference in whether the HTTP server sees a field named
"test.jpg" with a value of "image1", or sees a field named "image1" with
a value of "test.jpg".

I'm break pointing the server and there are no parameter or files in the
THttpRequest that is passed to the OnExecuteRequest event.

Then the problem has to be in how IntraWeb is parsing the POST data, not
in how TIdHTTP is sending it. I know for a fact that TIdHTTP.Post(TIdMultipartFormDataStream)
produces a legal and valid POST request. Feel free to Wireshark the request
and validate it for yourself.

--
Remy Lebeau (TeamB)
Paul Richardson

Posts: 10
Registered: 2/3/08
Re: Files list in THttpRequest is empty when called from indy client  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2016 5:49 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hello Remy,

Thank you for your reply. I am in no doubt that the Indy client is sending the correct request to the server and that the Intraweb Server is somehow not parsing the data in the same way that it used to. I was hoping that as this is posted in the Intraweb forum that someone from Intraweb may be able to comment on it but so far no luck.

Paul

Remy Lebeau (TeamB) wrote:
Paul wrote:

the order of the parameters doesn't make any difference.

Yes, it does. AddFormField('test.jpg','image1') produces this POST data:

--boundary
Content-Disposition: form-data; name="test.jpg"
 
image1


Whereas AddFormField('image1','test.jpg') produces this POST data instead:

--boundary
Content-Disposition: form-data; name="image1"
 
test.jpg


That makes a BIG difference in whether the HTTP server sees a field named
"test.jpg" with a value of "image1", or sees a field named "image1" with
a value of "test.jpg".

I'm break pointing the server and there are no parameter or files in the
THttpRequest that is passed to the OnExecuteRequest event.

Then the problem has to be in how IntraWeb is parsing the POST data, not
in how TIdHTTP is sending it. I know for a fact that TIdHTTP.Post(TIdMultipartFormDataStream)
produces a legal and valid POST request. Feel free to Wireshark the request
and validate it for yourself.

--
Remy Lebeau (TeamB)
Alexandre Machado

Posts: 1,754
Registered: 8/10/13
Re: Files list in THttpRequest is empty when called from indy client  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 17, 2016 2:46 AM   in response to: Paul Richardson in response to: Paul Richardson
Hi Paul,

Add these fields to your request header:

X-IWFileUploader=True

You can also add this optional field:

X-File-Name='Myfile.jpg'

This way, Myfile.jpg will be parsed

IntraWeb, by default, does not parse any content, unless it is a known content (content type is pre-registered, or IntraWeb knows that it was sent by a known control, like IWFileUploader)

PS: If you have a small test case application (both the Indy client and the IW server) I can take a look for you.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02