Swift File Upload

Upload Files from Swift Using URLSession (iOS & macOS)

Upload files from Swift with URLSession multipart. No SDK, REST API, CDN delivery, prepaid credits.

On Apple platforms, URLSession is the right tool for uploading user files, and it covers the entire files.link flow with no Cocoapod and no Swift Package dependency. The AWSS3 pod drags in AWSCore and a stack of categories that bloat your app binary and complicate App Store review; files.link is three URLSession requests that your app already has the capability to make.

The critical Swift-specific detail is uploadTask(with:fromFile:). Unlike data(for:), an upload task backed by a file URL can run as a background URLSession, meaning a large photo or video keeps uploading even after the user backgrounds your app or the screen locks — exactly what user-generated content apps need. The three steps: POST metadata to /v1/files/{folderId} with the raw API key in the Authorization header (no Bearer prefix), read the presigned url and id from the urls array, PUT the file with an upload task, then POST { ids: [id] } to /v1/files/confirm-upload.

swift
struct Slot: Decodable { let url: String; let id: String }
struct UploadResponse: Decodable { let success: Bool; let urls: [Slot] }

func upload(folderId: String, fileURL: URL) async throws -> String {
    let key = ProcessInfo.processInfo.environment["FILESLINK_KEY"]!
    var req = URLRequest(url: URL(string: "https://api.files.link/v1/files/\(folderId)")!)
    req.httpMethod = "POST"; req.setValue(key, forHTTPHeaderField: "Authorization")
    req.setValue("application/json", forHTTPHeaderField: "Content-Type")
    req.httpBody = try JSONEncoder().encode(["name": fileURL.lastPathComponent])
    let (d, _) = try await URLSession.shared.data(for: req)
    let slot = try JSONDecoder().decode(UploadResponse.self, from: d).urls[0]

    var put = URLRequest(url: URL(string: slot.url)!); put.httpMethod = "PUT"
    _ = try await URLSession.shared.upload(for: put, fromFile: fileURL)

    var confirm = URLRequest(url: URL(string: "https://api.files.link/v1/files/confirm-upload")!)
    confirm.httpMethod = "POST"; confirm.setValue(key, forHTTPHeaderField: "Authorization")
    confirm.setValue("application/json", forHTTPHeaderField: "Content-Type")
    confirm.httpBody = try JSONEncoder().encode(["ids": [slot.id]])
    _ = try await URLSession.shared.data(for: confirm)
    return slot.id
}

From SwiftUI, call this inside a Task and feed the resulting CDN URL straight into AsyncImage. The same code compiles unchanged for macOS, watchOS, and tvOS. One important security note: a shipped iOS app cannot hide an embedded API key from a determined attacker, so for production consumer apps mint upload credentials from your own backend rather than baking the master key into the binary. Files are encrypted at rest, visibility is per file, and billing is prepaid credits.

Benefits With No Complexity

Global CDN delivery

Your files are served from 450+ edge locations worldwide.

Edge-cached worldwide

Files are cached close to your users for fast delivery.

Signed-URL security

Private files stay protected with time-limited access.

What You Get

Unlimited files

Upload as many files as you need.

Unlimited storage

There is no storage limit.

Public + Private storage

Private files are fully secured.

CDN ready links

Upload directly to 450+ edge locations worldwide.

Prepaid credits

No subscription. Pay only for the storage and bandwidth you use.

More coming soon

We have plenty of features coming!

How files.link Works

1. Upload

Create a project and upload your first file.

2. Copy

Copy the CDN link.

3. Use Anywhere

Paste and enjoy the blazing speed.

Why Developers Choose files.link

A Better Way to Store & Deliver Files

AWS S3 (AWSS3 pod)Firebase Storage SDKfiles.link
Works with URLSession (no pod / SPM dependency)
Background uploads via upload(fromFile:)
Global CDN delivery on every file
Smaller app binary (no vendor framework)
Prepaid credits (no surprise bills)

Calculate Your Needs

Storage

0GB

Egress

0GB

CDN Bandwidth

0GB
Total: $0.000/month

Upload Files from Swift

  • Global CDN delivery
  • Edge-cached worldwide
  • Signed-URL security
  • Unlimited files
  • Unlimited storage
  • Public + Private storage
  • No subscription — prepaid credits keep spend predictable
Start Uploading from Swift

Frequently Asked Questions

Do I need the AWSS3 Cocoapod or any SPM package?
No. URLSession handles the metadata POST, the presigned PUT, and the confirm POST natively. Skipping the vendor framework keeps your app binary smaller and your App Store review simpler.
Can uploads continue when the app is backgrounded?
Yes. Use a background URLSession with uploadTask(with:fromFile:). iOS hands the transfer to the system, so a large photo or video keeps uploading even after the user leaves your app.
How do I show the uploaded image in SwiftUI?
After confirm-upload you get a CDN URL. Pass it directly to AsyncImage(url:). Public files resolve over the global CDN; private files are served via short-lived signed URLs you fetch from your backend.
Is it safe to embed the API key in an iOS app?
No production app should ship the master key in its binary — it can be extracted. Mint scoped upload credentials from your own server and have the app call that, keeping the master key server-side.
Does the same code work on macOS and tvOS?
Yes. URLSession is identical across iOS, macOS, watchOS, and tvOS, so the three-call upload function compiles and runs unchanged on every Apple platform.
General Questions
Is there a subscription?
No. files.link uses prepaid credits, so storage, bandwidth, and API usage are deducted from your balance as you go. The app explains the payment step before uploads are enabled — no monthly subscription and no per-user fees.
What is files.link?
files.link is a developer-first file platform that makes it simple to store, secure, and deliver files globally. It provides signed URLs, public/private access, and an API-first design so you can integrate file delivery into any app without the usual complexity.
How does billing work?
files.link uses prepaid credits. As you use storage, bandwidth, and API requests, credits are deducted daily. When your balance runs low, we automatically recharge it using your saved card. If an auto-recharge doesn't go through, your files and links stay put — you simply update your payment method or top up manually to keep going. No monthly subscriptions — just simple usage-based pricing.
How secure is my data?
All files are encrypted at rest and in transit. You can use signed URLs for private files, control access with permissions, and rely on enterprise-grade infrastructure for data protection.

Related

files.link
Copyright © 2026
All rights reserved
ContactGuidesGlossaryStatusLegal