Sample code for 30+ languages & platforms
Visual FoxPro

REST File Upload (multipart/form-data)

See more REST Examples

Demonstrates how to upload a file using multipart/form-data.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loRest
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loFileStream
LOCAL lcResponseBody

lnSuccess = 0

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loRest = CreateObject('Chilkat.Rest')

* Connect to the HTTP server using TLS.
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
* Make sure to replace "www.chilkatsoft.com" with your domain..
lnSuccess = loRest.Connect("www.chilkatsoft.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    CANCEL
ENDIF

loFileStream = CreateObject('Chilkat.Stream')
loFileStream.SourceFile = "qa_data/jpg/starfish.jpg"

loRest.AddHeader("Content-Type","multipart/form-data")

loRest.PartSelector = "1"
loRest.AddHeader("Content-Type","image/jpg")
loRest.AddHeader("Content-Disposition",'form-data; name="filename"; filename="starfish.jpg"')
loRest.SetMultipartBodyStream(loFileStream)
loRest.PartSelector = "0"

lcResponseBody = loRest.FullRequestMultipart("POST","/the_uri_path_to_receive_the_upload")
IF (loRest.LastMethodSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loFileStream
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "Received error response code: " + STR(loRest.ResponseStatusCode)
    RELEASE loRest
    RELEASE loFileStream
    CANCEL
ENDIF

? "File uploaded"

RELEASE loRest
RELEASE loFileStream