Re: HTTPS file upload and idhttp component

Giganews Newsgroups
Subject: Re: HTTPS file upload and idhttp component
Posted by:  Remy Lebeau (TeamB) (no.spam@no.spam.com)
Date: Mon, 2 May 2005

"MikeR" <NOnf4lSP…@nf4l.com> wrote in message
news:65F0805937C9E240NOnf4lSP…@nf4l.com...

> What is the meaning of the colored properties in the property inspector
> (IOHandler, CookieManager and Intercept)? I have set none of these
> properties.

You can ignore the CookieManager and Intercept for the purposes of this
discussion.

> Here's what I have so far, and it throws an exception on the post with
> the message 'IOHandler value is not valid'. The return variable, FMS
> is empty. Anyone know how to resolve that?

You need to assign a TIdSSLIOHandlerSocket component to the IOHandler
property in order to access HTTPS URLs.

>    boundary := '012345';
>    params := '--' + Boundary + CCRLF;
>    params := params + 'Content-Disposition: form-data; name="upfile";';
>    params := params + ' FileName = "' + FileP + '"' +  CCRLF;
>    params := params + 'Content-Type: text/plain' + CCRLF + CCRLF;
>    params := params + FileC + CCRLF;
>    params := params + '--' + Boundary + CCRLF;
>
>    IdHTTP1.Request.ContentType := 'multipart/form-data; boundary="' +
boundary + '"';

I would suggest you use a TIdMultiPartFormDataStream instead.
TIdHTTP.Post() has an overloaded version that accepts
TIdMultiPartFormDataStream as input, ie:

    procedure TfrmExpOpts.UploadFile(fnm: string);
    var
        PMS: TIdMultiPartFormDataStream;
        FMS: TStream;
    begin
        try
            PMS := TIdMultiPartFormDataStream.Create;
            try
                PMS.AddFile('upfile', frmLog.AppDir + '\' + frmLog.CurrUser
+ '.xxx', 'text/plain');
                FMS := TMemoryStream.Create;
                try
                    IdHTTP1.Post('https://www.someserver.org/varx/upload',
PMS, FMS);
                    // use FMS as needed...
                finally
                    FMS.Free;
                end;
            finally
                PMS.Free;
            end;
        except
            on E: Exception do ShowMessage('Error encountered during POST: '
+ E.Message);
        end;
    end;

Gambit

Replies

In response to

HTTPS file upload and idhttp component posted by MikeR on Sun, 01 May 2005