Answer the question
In order to leave comments, you need to log in
How to send post with file and parameter?
Hello!
You need to send a post request to the server (php) and pass in it the parameter user (string) and image (file)
the image is stored in TImage (this is a screenshot)
I prepare the image like this:
image_ms := TMemoryStream.Create;
jpg := TJPEGImage.Create;
jpg.Assign(Image1.Picture.Graphic);
Image1.Free;
jpg.CompressionQuality := 80;
jpg.Compress;
jpg.SaveToStream(image_ms);
Stream := TIdMultipartFormDataStream.Create;
Stream.AddFormField('user', user_id);
result := IdHTTP1.Post('https://site.ru/upload.php', Stream);
Stream.Free;
Answer the question
In order to leave comments, you need to log in
Depends on how the server accepts it. You can pass it inside MultipartFormDataStream, or you can send it in base64 format in the same MultipartFormDataStream.
And I recommend using not Indy, but Sytem.Net.HttpClient.
And in Indy, the file transfer happens like this:
MultipartFormDataStream.AddFile('file', 'C:\test.rar', 'application/octet-stream');
или
MultipartFormDataStream.AddFile('file', 'test.jpg', 'application/octet-stream', image_ms);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question