Alamofire: Support for loading multi-page forms with text and file parts?

Alamofire now has support for multipart form uploads.

However, looking at the API of the MultipartFormData class, I don't see an obvious way to send heterogeneous data - plain / json text data along with the intended binary data. In my reading - in its current form, it seems more oriented as downloading multiple files (binary stream) with no support for text or json parts.

Am I missing something? How do I load text / json data pieces along with the intended file data pieces? Is there any sample code that does this?

To be complete, I've written extensions to fill in some of them, but all the time I feel like there should be an easier way (my changes require some modification to Alamofire).

So, and for what it's worth, here's my attempt in pure form:

multipartFormData: { form in
    form.appendBodyPart(Multipart.plain("person", text:"\(last.id)")!)
    form.appendBodyPart(Multipart.json("thing", parameters:parameters)!)
    form.appendBodyPart(fileURL: puppyFile, name: "file") },

      

Obviously the maintainable solution is better than the reinvented wheel, so the question is.

PS. I'm posting this year as per Alamofire documentation, SO is the preferred vehicle for help and discussion.

+3


source to share


1 answer


This was not supported at the time of my post, but has been implemented since then in the branch multipart_form

for version 1.3 currently available. This is due to the fact that:



https://github.com/Alamofire/Alamofire/pull/596

+1


source







All Articles