Skip to content

How to upload files with Async/Await? #58

Answered by s4cha
loganx510 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, the api is not available per se (yet) but there is a way to use an AnyPublisher api in an async-await fashion via values property. Here is an example below:

func updateAvatar(user: User, data: Data) async throws {
    let multipart = MultipartData(name: "avatar", fileData: data, fileName: "photo.jpg", mimeType: "image/jpeg")
    for try await (data, progress) in network.put("users/\(user.id)/avatar", multipartData: multipart).values where data != nil {
        break
    }
}

Hope this helps :)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@loganx510
Comment options

Answer selected by loganx510
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants