Storage
Upload
Section titled “Upload”let imageData: Data = /* file content */
let file = try await client.files.upload( data: imageData, filename: "photo.jpg", mimeType: "image/jpeg")print(file.id)print(file.key)Upload with progress
Section titled “Upload with progress”let file = try await client.files.upload( data: videoData, filename: "video.mp4", mimeType: "video/mp4", options: UploadOptions( bucket: "media", isPublic: true, onProgress: { pct in DispatchQueue.main.async { progressView.setProgress(Float(pct), animated: true) } } ))Associate with a record
Section titled “Associate with a record”let file = try await client.files.upload( data: avatarData, filename: "avatar.jpg", mimeType: "image/jpeg", options: UploadOptions( collection: "users", recordId: userId, bucket: "avatars" ))Download
Section titled “Download”let data = try await client.files.download(id: file.id)let image = UIImage(data: data)Public URL
Section titled “Public URL”// For public files only — no authentication requiredlet url = client.files.publicUrl(id: file.id, filename: "photo.jpg")Signed URL (private files)
Section titled “Signed URL (private files)”// Default 1-hour expirylet url = try await client.files.signedUrl(id: file.id)
// Custom expiry (seconds)let url = try await client.files.signedUrl(id: file.id, expiresIn: 7200)Pre-signed upload (S3 / large files)
Section titled “Pre-signed upload (S3 / large files)”let result = try await client.files.signedUpload( filename: "large-video.mp4", contentType: "video/mp4", options: UploadOptions(bucket: "videos"), expiresIn: 3600)
// Upload directly to result.url with a plain PUT requestvar req = URLRequest(url: URL(string: result.url)!)req.httpMethod = "PUT"req.setValue("video/mp4", forHTTPHeaderField: "Content-Type")req.httpBody = videoData_ = try await URLSession.shared.data(for: req)let files = try await client.files.list(limit: 50, page: 1)for file in files { print("\(file.filename ?? "?") — \(file.size) bytes") }Delete
Section titled “Delete”try await client.files.delete(id: file.id)