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
(Unicode C) S3 Upload Binary File from BinDataSee more Amazon S3 (new) ExamplesUpload a binary file contained in a BinData object to Amazon S3.
#include <C_CkRestW.h> #include <C_CkAuthAwsW.h> #include <C_CkBinDataW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkRestW rest; BOOL bTls; int port; BOOL bAutoReconnect; BOOL success; HCkAuthAwsW authAws; HCkBinDataW pngData; HCkStringBuilderW sbResponse; int statusCode; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. rest = CkRestW_Create(); // Connect to the Amazon AWS REST server. bTls = TRUE; port = 443; bAutoReconnect = TRUE; // Make sure to connect to the region where the bucket is located.. success = CkRestW_Connect(rest,L"s3-us-west-2.amazonaws.com",port,bTls,bAutoReconnect); // Provide AWS credentials for the REST call. authAws = CkAuthAwsW_Create(); CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY"); CkAuthAwsW_putSecretKey(authAws,L"AWS_SECRET_KEY"); // Use the correct region.. CkAuthAwsW_putRegion(authAws,L"us-west-2"); CkAuthAwsW_putServiceName(authAws,L"s3"); success = CkRestW_SetAuthAws(rest,authAws); // Set the bucket name via the HOST header. // In this case, the bucket name is "chilkat.qa". // (Also make sure to use the correct region.) CkRestW_putHost(rest,L"chilkat.qa.s3-us-west-2.amazonaws.com"); // Load a text file into memory. pngData = CkBinDataW_Create(); success = CkBinDataW_LoadFile(pngData,L"qa_data/png/anemone.png"); if (success != TRUE) { wprintf(L"Failed to load file from local filesystem.\n"); CkRestW_Dispose(rest); CkAuthAwsW_Dispose(authAws); CkBinDataW_Dispose(pngData); return; } // Indicate the Content-Type of our upload. (This is optional) CkRestW_AddHeader(rest,L"Content-Type",L"image/png"); // Upload the file to Amazon S3. sbResponse = CkStringBuilderW_Create(); success = CkRestW_FullRequestBd(rest,L"PUT",L"/images/sea_creatures/anemone.png",pngData,sbResponse); if (success != TRUE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkRestW_Dispose(rest); CkAuthAwsW_Dispose(authAws); CkBinDataW_Dispose(pngData); CkStringBuilderW_Dispose(sbResponse); return; } // Did we get a 200 response indicating success? statusCode = CkRestW_getResponseStatusCode(rest); if (statusCode != 200) { wprintf(L"Error response: %s\n",CkStringBuilderW_getAsString(sbResponse)); wprintf(L"Status code: %d, Status text: %s\n",statusCode,CkRestW_responseStatusText(rest)); CkRestW_Dispose(rest); CkAuthAwsW_Dispose(authAws); CkBinDataW_Dispose(pngData); CkStringBuilderW_Dispose(sbResponse); return; } wprintf(L"File successfully uploaded.\n"); CkRestW_Dispose(rest); CkAuthAwsW_Dispose(authAws); CkBinDataW_Dispose(pngData); CkStringBuilderW_Dispose(sbResponse); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.