Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Visual FoxPro) REST File Upload (multipart/form-data)Demonstrates how to upload a file using multipart/form-data.
LOCAL loRest LOCAL lnBTls LOCAL lnPort LOCAL lnBAutoReconnect LOCAL lnSuccess LOCAL loFileStream LOCAL lcResponseBody * This example requires the Chilkat API to have been previously unlocked. * See Global Unlock Sample for sample code. * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Rest') 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 * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Stream') 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 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.