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
(DataFlex) REST File Upload (multipart/form-data)Demonstrates how to upload a file using multipart/form-data.
Use ChilkatAx-win32.pkg Procedure Test Handle hoRest Boolean iBTls Integer iPort Boolean iBAutoReconnect Boolean iSuccess Variant vFileStream Handle hoFileStream String sResponseBody String sTemp1 Integer iTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatRest)) To hoRest If (Not(IsComObjectCreated(hoRest))) Begin Send CreateComObject of hoRest End // Connect to the HTTP server using TLS. Move True To iBTls Move 443 To iPort Move True To iBAutoReconnect // Make sure to replace "www.chilkatsoft.com" with your domain.. Get ComConnect Of hoRest "www.chilkatsoft.com" iPort iBTls iBAutoReconnect To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoRest To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStream)) To hoFileStream If (Not(IsComObjectCreated(hoFileStream))) Begin Send CreateComObject of hoFileStream End Set ComSourceFile Of hoFileStream To "qa_data/jpg/starfish.jpg" Get ComAddHeader Of hoRest "Content-Type" "multipart/form-data" To iSuccess Set ComPartSelector Of hoRest To "1" Get ComAddHeader Of hoRest "Content-Type" "image/jpg" To iSuccess Get ComAddHeader Of hoRest "Content-Disposition" 'form-data; name="filename"; filename="starfish.jpg"' To iSuccess Get pvComObject of hoFileStream to vFileStream Get ComSetMultipartBodyStream Of hoRest vFileStream To iSuccess Set ComPartSelector Of hoRest To "0" Get ComFullRequestMultipart Of hoRest "POST" "/the_uri_path_to_receive_the_upload" To sResponseBody Get ComLastMethodSuccess Of hoRest To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoRest To sTemp1 Showln sTemp1 Procedure_Return End Get ComResponseStatusCode Of hoRest To iTemp1 If (iTemp1 <> 200) Begin Get ComResponseStatusCode Of hoRest To iTemp1 Showln "Received error response code: " iTemp1 Procedure_Return End Showln "File uploaded" End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.