Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Swift) Initiate Resumable Upload SessionSee more Google Cloud Storage ExamplesInitiate a Google Cloud Storage resumable upload session.. For more information, see https://cloud.google.com/storage/docs/performing-resumable-uploads
func chilkatTest() { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. let http = CkoHttp()! let jsonToken = CkoJsonObject()! var success: Bool = jsonToken.loadFile("qa_data/tokens/googleCloudStorage.json") if success == false { print("\(jsonToken.lastErrorText!)") return } let jsonMetaData = CkoJsonObject()! jsonMetaData.update("contentType", value: "image/jpeg") // Adds the "Authorization: Bearer <access_token>" header.. http.authToken = jsonToken.string(of: "access_token") http.setUrlVar("bucket_name", value: "chilkat-bucket-b") http.setUrlVar("object_name", value: "penguins2.jpg") var url: String? = "https://storage.googleapis.com/upload/storage/v1/b/{$bucket_name}/o?uploadType=resumable&name={$object_name}" var resp: CkoHttpResponse? = http.pText("POST", url: url, textData: jsonMetaData.emit(), charset: "utf-8", contentType: "application/json", md5: false, gzip: false) if http.lastMethodSuccess == false { print("\(http.lastErrorText!)") return } var statusCode: Int = resp!.statusCode.intValue print("response status code = \(statusCode)") var sessionUrl: String? = "" if statusCode != 200 { print("\(resp!.bodyStr!)") } else { // The session URL will be used to upload the file in chunks, in subsequent HTTP POSTs... sessionUrl = resp!.getHeaderField("Location") print("Session URL = \(sessionUrl!)") } resp = nil } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.