{"id":22632436,"url":"https://github.com/uploadcare/uploadcare-swift","last_synced_at":"2025-08-24T02:14:41.851Z","repository":{"id":37852583,"uuid":"229274849","full_name":"uploadcare/uploadcare-swift","owner":"uploadcare","description":"Swift API client for iOS, iPadOS, tvOS, macOS, and Linux handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.","archived":false,"fork":false,"pushed_at":"2024-10-11T06:21:41.000Z","size":25402,"stargazers_count":12,"open_issues_count":8,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-13T18:09:04.197Z","etag":null,"topics":["api","client","file-upload","image-processing","image-recognition","image-upload","ios","linux","macos","processing","sdk","swift","upload","uploadcare","uploader"],"latest_commit_sha":null,"homepage":"https://uploadcare.com/","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uploadcare.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-20T13:59:22.000Z","updated_at":"2024-05-29T14:04:07.000Z","dependencies_parsed_at":"2023-11-16T00:27:00.207Z","dependency_job_id":"e0d1394f-eeee-4c4d-9856-589c986196c7","html_url":"https://github.com/uploadcare/uploadcare-swift","commit_stats":{"total_commits":524,"total_committers":5,"mean_commits":104.8,"dds":"0.12022900763358779","last_synced_commit":"416039ae0c5dfdf9769b0ba4c42751086edd02ea"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/uploadcare/uploadcare-swift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uploadcare%2Fuploadcare-swift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uploadcare%2Fuploadcare-swift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uploadcare%2Fuploadcare-swift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uploadcare%2Fuploadcare-swift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uploadcare","download_url":"https://codeload.github.com/uploadcare/uploadcare-swift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uploadcare%2Fuploadcare-swift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260322251,"owners_count":22991795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","client","file-upload","image-processing","image-recognition","image-upload","ios","linux","macos","processing","sdk","swift","upload","uploadcare","uploader"],"created_at":"2024-12-09T02:17:34.732Z","updated_at":"2025-06-17T12:38:08.651Z","avatar_url":"https://github.com/uploadcare.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Swift API client for Uploadcare\n\n![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fuploadcare%2Fuploadcare-swift%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/uploadcare/uploadcare-swift)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fuploadcare%2Fuploadcare-swift%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/uploadcare/uploadcare-swift)\n[![Build and test](https://github.com/uploadcare/uploadcare-swift/actions/workflows/test.yml/badge.svg)](https://github.com/uploadcare/uploadcare-swift/actions/workflows/test.yml)\n\nUploadcare Swift API client for iOS, iPadOS, tvOS and macOS handles uploads and further operations with files by wrapping Uploadcare Upload and REST APIs.\n\nCheck out our [Demo App](/Demo).\n\n* [Installation](#installation)\n* [Initialization](#initialization)\n* [Using Upload API](#using-upload-api)\n* [Using REST API](#using-rest-api)\n* [Demo app](#demo-app)\n* [Useful links](#useful-links)\n\n## Installation\n\n### Swift Package Manager\n\nTo use a stable version, add a dependency to your `Package.swift` file:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/uploadcare/uploadcare-swift.git\", .branch(\"master\"))\n]\n```\n\nIf you want to try the current dev version, change the dependency to:\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/uploadcare/uploadcare-swift.git\", branch(\"develop\"))\n]\n```\n\nTo add from Xcode select File -\u003e Swift Packages -\u003e Add Package Dependency and enter the repository URL:\n```\nhttps://github.com/uploadcare/uploadcare-swift\n```\n\nOr you can add it in Xcode to the packages list using that URL: https://github.com/uploadcare/uploadcare-swift (select master branch).\n\n### Carthage\n\nTo use a stable version, add a dependency to your Cartfile:\n\n```\ngithub \"uploadcare/uploadcare-swift\"\n```\n\nTo use the current dev version:\n\n```\ngithub \"uploadcare/uploadcare-swift\" \"develop\"\n```\n\n### Cocoapods\n\nTo use a stable version, add a dependency to your Podfile:\n\n```\npod 'Uploadcare', git: 'https://github.com/uploadcare/uploadcare-swift'\n```\n\nTo use current dev version:\n\n```\npod 'Uploadcare', git: 'https://github.com/uploadcare/uploadcare-swift', :branch =\u003e 'develop'\n```\n\n## Initialization\n\nCreate your project in [Uploadcare dashboard](https://uploadcare.com/dashboard/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=uploadcare-swift) and copy its API keys from there.\n\nUpload API requires only a public key, while REST API requires both public and secret keys:\n\n```swift\nfinal class MyClass {\n    private var uploadcare: Uploadcare\n    \n    init() {\n        self.uploadcare = Uploadcare(withPublicKey: \"YOUR_PUBLIC_KEY\")\n        \n        // Secret key is optional if you want to use Upload API only.\n        // REST API requires both public and secret keys:\n        self.uploadcare = Uploadcare(withPublicKey: \"YOUR_PUBLIC_KEY\", secretKey: \"YOUR_SECRET_KEY\")\n    }\n}\n```\n\nYou can create more Uploadcare objects if you need to work with multiple projects in your Uploadcare account:\n\n```swift\nfinal class MyClass {\n    private let project1: Uploadcare\n    private let project2: Uploadcare\n    \n    init() {\n        // A project to use Upload API only \n        self.project1 = Uploadcare(withPublicKey: \"YOUR_PUBLIC_KEY_1\")\n\n        // A project to use both REST API and Upload API\n        self.project2 = Uploadcare(withPublicKey: \"YOUR_PUBLIC_KEY_2\", secretKey: \"YOUR_SECRET_KEY_2\")\n    }\n}\n```\n\nKeep in mind that since Uploadcare is not a singleton. You should store a strong reference (as an instance variable, for example) to your Uploadcare object or it will get deallocated.\n\n## Using Upload API\n\nCheck the [Upload API documentation](https://github.com/uploadcare/uploadcare-swift/blob/master/Documentation/Upload%20API.md) to see all available methods. Each method has an implementation with a `Result` completion handler and has an alternative `async` implementation to use with Swift concurrency.\n\nExample of uploads:\n\n```swift\nguard let url = URL(string: \"https://ucarecdn.com/46528d0d-323c-42d7-beab-2fdc5e7077ba/\") else { return }\nguard let data = try? Data(contentsOf: url) else { return }\n\n// You can create an UploadedFile object to operate with it\nvar fileForUploading1 = uploadcare.file(fromData: data)\nfileForUploading2.metadata = [\"myKey\": \"myValue\"]\ntry await fileForUploading1.upload(withName: \"random_file_name.jpg\", store: .auto)\n\n// Or you can just upload data and provide a filename\n\nvar fileForUploading2 = uploadcare.file(withContentsOf: url)!\nlet file = try await uploadcare.uploadFile(data, withName: \"random_file_name.jpg\", store: .auto) { progress in\n    print(\"upload progress: \\(progress * 100)%\")\n}\n\n// Same method with a completion callback that returns a task that can be paused or canceled:\nlet task = uploadcare.uploadFile(data, withName: \"random_file_name.jpg\", store: .auto, metadata: [\"someKey\": \"someMetaValue\"]) { progress in\n    print(\"upload progress: \\(progress * 100)%\")\n} _: { result in\n    switch result {\n    case .failure(let error):\n        print(error.detail)\n    case .success(let file):\n        print(file)\n    }\n}\n// Cancel uploading if needed\ntask.cancel()\n\n// task will confirm UploadTaskable protocol if file size is less than 100 mb, and UploadTaskResumable if file size is \u003e= 100mb\n// You can pause or resume uploading of file with size \u003e= 100mb if needed\n(task as? UploadTaskResumable)?.pause()\n(task as? UploadTaskResumable)?.resume()\n```\n\nIt is possible to perform uploads in the background. But implementation is platform-specific. This lib doesn't provide a default implementation. You can find an example for the iOS in our Demo app. See [FilesListStore.swift](https://github.com/uploadcare/uploadcare-swift/blob/1e6341edcdcb887589a4e798b746c525c9023b4e/Demo/Demo/Modules/FilesListStore.swift).\n\n## Using REST API\n\nRefer to the [REST API documentation](https://github.com/uploadcare/uploadcare-swift/blob/master/Documentation/REST%20API.md) for all methods. Each method has an implementation with a `Result` completion handler and has an alternative `async` implementation to use with Swift concurrency.\n\nExample of getting list of files:\n\n```swift\n// Make a list of files object\nlazy var filesList = uploadcare.listOfFiles()\n\nfunc someFilesListMethod() {\n    // Make a query object\n    let query = PaginationQuery()\n        .stored(true)\n        .ordering(.dateTimeUploadedDESC)\n        .limit(5)\n\n    // Get file list\n    let list = try await filesList.get(withQuery: query)\n    \n    // Same method with a completion callback.\n    filesList.get(withQuery: query) { result in\n        switch result {\n        case .failure(let error):\n            print(error)\n        case .success(let list):\n            print(list)\n        }\n    }\n}\n```\n\nGet next page:\n\n```swift\n// Check if the next page is available\nguard filesList.next != nil else { return }\n\n// Async:\nlet next = try await filesList.nextPage()\n\n// With a completion callback:\nfilesList.nextPage { result in\n    switch result {\n    case .failure(let error):\n        print(error)\n    case .success(let list):\n        print(list)\n    }\n}\n```\n\nGet previous page:\n\n```swift\n// Check if the previous page is available\nguard filesList.previous != nil else { return }\n\n// Async:\nlet previous = try await filesList.previousPage()\n\n// With a completion callback:\nfilesList.previousPage { result in\n    switch result {\n    case .failure(let error):\n        print(error)\n    case .success(let list):\n        print(list)\n    }\n}\n```\n\n## Demo app\n\nCheck the [demo app](https://github.com/uploadcare/uploadcare-swift/tree/master/Demo) for usage examples: \n* List of files\n* List of groups\n* File info\n* File upload (both direct and multipart, including upload in background)\n* Multiple file upload\n* Pause and continue multipart uploading\n* Project info\n\n## Useful links\n\n[Swift Upload API client documentation](https://github.com/uploadcare/uploadcare-swift/blob/master/Documentation/Upload%20API.md)  \n[Swift REST API client documentation](https://github.com/uploadcare/uploadcare-swift/blob/master/Documentation/REST%20API.md)  \n[Uploadcare documentation](https://uploadcare.com/docs/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=uploadcare-swift)  \n[Upload API reference](https://uploadcare.com/api-refs/upload-api/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=uploadcare-swift)  \n[REST API reference](https://uploadcare.com/api-refs/rest-api/v0.7.0/?utm_source=github\u0026utm_medium=referral\u0026utm_campaign=uploadcare-swift)  \n[Contributing guide](https://github.com/uploadcare/.github/blob/master/CONTRIBUTING.md)  \n[Security policy](https://github.com/uploadcare/uploadcare-swift/security/policy)  \n[Support](https://github.com/uploadcare/.github/blob/master/SUPPORT.md)  \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuploadcare%2Fuploadcare-swift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuploadcare%2Fuploadcare-swift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuploadcare%2Fuploadcare-swift/lists"}