SkillAgentSearch skills...

MultipartForm

The missing multipart form support for URLSession.

Install / Use

/learn @davbeck/MultipartForm
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

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.

Related Skills

View on GitHub
GitHub Stars44
CategoryCustomer
Updated1y ago
Forks6

Languages

Swift

Security Score

75/100

Audited on May 18, 2024

No findings