Skip to content

Commit

Permalink
Merge pull request #511 from pennlabs/anli/03-15-multipart-builder-sy…
Browse files Browse the repository at this point in the history
…ntax

Use MultipartBuilder syntax in SublettingAPI
  • Loading branch information
JHawk0224 authored Mar 15, 2024
2 parents 724aab8 + fd5b296 commit 4605cd9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions PennMobile/Subletting/SublettingAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,15 @@ public class SublettingAPI {
throw NetworkingError.serverError
}

let boundary = MultipartBody.generateBoundary()
let idPart = try MultipartContent(name: "sublet", content: "\(id)")
let imagesPart = images.enumerated().compactMap { index, image -> MultipartContent? in
guard let imageData = image.jpegData(compressionQuality: 0.8) else { return nil }
return MultipartContent(type: "image/jpeg", name: "images", filename: "image\(index).jpeg", data: imageData)
let multipartBody = try MultipartBody {
try MultipartContent(name: "sublet", content: "\(id)")

for (index, image) in images.enumerated() {
if let imageData = image.jpegData(compressionQuality: 0.8) {
MultipartContent(type: "image/jpeg", name: "images", filename: "image\(index).jpeg", data: imageData)
}
}
}
let multipartBody = try MultipartBody(boundary: boundary, content: [idPart] + imagesPart)

var request = URLRequest(url: url)
request.httpMethod = "POST"
Expand Down

0 comments on commit 4605cd9

Please sign in to comment.