Swiftpack.co - davbeck/MultipartForm as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by davbeck.
davbeck/MultipartForm 0.1.0
The missing multipart form support for URLSession.
⭐️ 36
🕓 4 weeks ago
.package(url: "https://github.com/davbeck/MultipartForm.git", from: "0.1.0")


A simple way to create multipart form requests in Swift.


import MultipartForm

let form = MultipartForm(parts: [
	MultipartForm.Part(name: "a", value: "1"),
	MultipartForm.Part(name: "b", value: "2"),
	MultipartForm.Part(name: "c", data: imageData, filename: "3.png", contentType: "image/png"),

var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue(form.contentType, forHTTPHeaderField: "Content-Type")

let task = session.uploadTask(with: request, from: form.bodyData)

To upload a file in the background, you can write out form.bodyData to a file and create an upload task from that.


Stars: 36
Last commit: 4 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics