wwHTTP::AddPostFile

A specific version of AddPostKey() designed for File or Data uploads for multi-part HTTP forms.

This method requires that nHttpPostMode=2. If not set an error occurs.

This method provides extra parameters for a file name or data, the name of the file, content type and any extra mime headers that might have to be added to a 'data' field that needs to be uploaded.

o.AddPostFile(tcKey, tcValue, 
             tlIsFile, tcContentType, 
             tcExtraHeaders)

Return Value

nothing

Parameters

tcKey
The key value to set. One special value can also be used:

RESET - clears any existing POST data. No value is required to be passed in this case. If you call AddPostKey with no paramters at all the POST buffer is also cleared.

BLANK - ("" or omitted) if this value is empty or not provided tcValue will be used to write the entire POST buffer unencoded. Use for XML documents or anything where you need to post a raw POST buffer.

tcValue
The value to set the key to. In combination these values are equivalent to a Form Variable name and value.

Multi-Part Forms specific parameters

tlIsFile
If this value is set to .T. the second parameter is a filename on disk that is to be uploaded to the Server. NOTE: This only works if nHTTPPostMode = 2 otherwise this option is omitted.

tcContentType
Optional content type for the value in multi-part forms mode (2). Use this for files if you want to explicitly specify the content type. If left blank this value is not set.

tcExtraHeaders
Extra headers to add to multi-part form mode (2) submissions other than content type. Each header is a full HTTP header on an individual line followed by CHR(13) + CHR(10).

lcHeader = "Content-Length: 400" + CRLF +;
           "X-Custom-Header: Custom" + CRLF +;
           "X-Custom-Header2: Custom2"

Remarks

UrlEncoded content that is longer than 254 characters requires wwIPStuff.dll for the URLEncoding using C++ code for better performance. This refers to the default nHttpPostMode value of 1.

Depending on the value of the nHTTPPostMode property forms are posted either in standard URLEncoded or Multi-Part form mode. Multi-part form mode can be more efficient for large uploads as no encoding takes place, but the server application must support parsing multi-part forms. Web Connection automatically handles this via Request.Form().

Example

loHTTP = CREATEOBJECT("wwHTTP")

*** Posting a multi-part form with a File Upload
loHTTP.nHttpPostMode = 2  && Multipart form encoding

*** Post a file and a regular form variable
loHttp.AddPostFile("File","d:\temp\wws_invoice.pdf",.T.)
loHttp.AddPostKey("txtFileNotes","test note")

lcHTML = loHTTP.Post("http://localhost/wconnect/FileUpload.wwd")

See also:

Class wwHttp | wwHTTP::nhttppostmode | wwHttp::AddPostKey

© West Wind Technologies, 2020 • Updated: 10/23/20
Comment or report problem with topic