Swift Package Index


The missing multipart form support for URLSession.


  • The latest stable release is 0.1.0. Released about 1 year ago.
  • The last commit to master was about 1 year ago.

Swift Version Compatibility

  • 0.1.0 and master
    5.3
    5.2
    5.1
    5.0
    4.2
Full build results

Platform Compatibility

  • 0.1.0 and master
    iOS
    macOS(Intel)
    macOS(ARM)
    Linux
    tvOS
    watchOS
Full build results

MultipartForm

A simple way to create multipart form requests in Swift.

Example

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)
task.resume()

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