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, tcFilename, tcPostedFilename, tcContentType, tcExtraHeaders)
Parameters
tcKey
The key for the uploaded file.
tcFilename
A local file to upload. The filename is retrieved either on a fully qualified path or a relative path based on the FoxPro path.
tcPostedFilename
Optional - This is the filename that is sent to the server and will be used if the file is downloaded later. This should be just the filename without a path. If not provided the filename is pulled from tcFilename
.
tcContentType
Optional content type for the value in multi-part forms mode (2). Use this for files or data if you want to explicitly specify the content type. If left blank this value is not set.
tcExtraHeaders
Optional 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",
"invoice.pdf", "application/pdf")
loHttp.AddPostKey("txtFileNotes","test note")
lcHTML = loHTTP.Post("http://localhost/wconnect/FileUpload.wwd")