Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
upload image with php file
#2
(06-17-2020, 05:05 PM)Madammar Wrote: i am using httpclient to post the file to  php

Since you are using Indy anyway, why are you using Embarcadero's THTTPClient and not Indy's TIdHTTP? Or, for that matter, why are you using Indy's TIdMultipartFormDataStream and not Embarcadero's TMultipartFormData? You really should not be mixing libraries like you are.

(06-17-2020, 05:05 PM)Madammar Wrote: the image doesnt seems to get uploaded and i get an empty response 

THTTPClient.Post() has no concept of TIdMultipartFormDataStream.  It just sees the stream as any other TStream object and posts its data as-is.  Which won't work in your case, because you are not setting the THTTPClient.ContentType property to specify the media type of the stream (multipart/form-data) or the MIME boundary that the stream uses between its MIME parts.  So the PHP script won't be able to parse the stream data correctly.

TIdHTTP.Post(), on the other hand, recognizes TIdMultipartFormDataStream and will set its own Request.ContentType property accordingly for you. So does THTTPClient.Post() with TMultipartFormData.

(06-17-2020, 05:05 PM)Madammar Wrote: what i am doing wrong ?

At the very least, if you are going to continue using TIdMultipartFormDataStream then you need to add the following line before calling THTTPClient.Post():

Code:
HttpClient.ContentType := PostData.RequestContentType;

Otherwise, use TMultipartFormData instead of TIdMultipartFormDataStream, or use TIdHTTP instead of THTTPClient.

Reply


Messages In This Thread
upload image with php file - by Madammar - 06-17-2020, 05:05 PM
RE: upload image with php file - by rlebeau - 06-17-2020, 07:24 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)