These are chat archives for IndySockets/Indy

Apr 2017
Apr 26 2017 09:54

Hi, Remy. I wonder, what Indy10 means by 'Content-Length' for TIdMultipartFormDataStream?

I have next code:

AMultiPartFormData := TIdMultipartFormDataStream.Create; // Size=-1, OK

AField := AMultiPartFormData.AddFormField(AId, '', '', 'application/octet-stream'); // size = 222, might be OK

DataStream.CopyFrom(AStream, ALength); // ALength = 100500 bytes
ADataStream.Position := 0;
AField.FieldStream := ADataStream; // after that size became even smaller 220 bytes! why? i expect to see it >= ALength

moreover i must also sent 'Content-MD5' header and have no idea what should be there... In previous version of code with Alcinoe library we had there
CalculateMD5ForStream(ADataStream); and everything works well!

Apr 26 2017 11:45
Should be ADataStream.Position := 0; before Post. But question about decreasing of size remains...
Remy Lebeau
Apr 26 2017 19:03
@icegood The Content-Length is the total bytes of the entire generated MIME content, from opening boundary to closing boundary, as one would expect. AMultiPartFormData.Size is not calculated until TIdHTTP requests it during posting, at which time the current field content is counted, but there is no way the size could be calculated so low, it takes the full MIME headers and FieldStream.Size into account (see TIdFormDataField.GetFieldSize()). How exactly are you determining the size is decreasing? You can use TIdHashMessageDigest5 to generate an MD5 hash, but there is currently no option to add custom headers to TIdMultipartFormDataStream fields, sorry.