Pre-1.0 Notice: This library is under active development. The API may change between minor versions until 1.0.
A Swift package for interacting with the Pinata API for IPFS file storage.
- Swift 6.0+
- iOS 15+ / macOS 12+ / watchOS 8+ / tvOS 15+ / visionOS 1+ / Linux
Add Pinata to your Package.swift:
dependencies: [
.package(url: "https://github.com/0xLeif/swift-pinata", from: "0.1.0")
]Then add the dependency to your target:
.target(
name: "YourApp",
dependencies: [
.product(name: "Pinata", package: "swift-pinata")
]
)Create a Pinata client with your credentials:
import Pinata
// Using JWT (recommended)
let pinata = Pinata(
jwt: "your-jwt-token",
gatewayDomain: "your-gateway.mypinata.cloud"
)
// Using API key
let pinata = Pinata(
apiKey: "your-api-key",
apiSecret: "your-api-secret",
gatewayDomain: "your-gateway.mypinata.cloud"
)// Upload data
let file = try await pinata.upload(
data: imageData,
name: "photo.jpg"
)
// Upload from file URL
let file = try await pinata.upload(
fileURL: localFileURL,
name: "document.pdf"
)
// Upload to a group
let file = try await pinata.upload(
data: data,
name: "file.txt",
groupId: "group-id"
)// List files
let files = try await pinata.listFiles(limit: 10)
// Get a specific file
let file = try await pinata.getFile(id: "file-id")
// Get gateway URL for a CID
if let url = await pinata.gatewayURL(for: file.cid) {
// Use URL to fetch content
}
// Delete a file
try await pinata.deleteFile(id: "file-id")// Create a group
let group = try await pinata.createGroup(name: "My Group")
// List groups
let groups = try await pinata.listGroups()
// Get a specific group
let group = try await pinata.getGroup(id: "group-id")
// Delete a group
try await pinata.deleteGroup(id: "group-id")Pinata is available under the MIT license. See the LICENSE file for more info.