This repository was archived by the owner on Sep 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Include parameters in multipart POST request #338
Open
fluiddot
wants to merge
4
commits into
trunk
Choose a base branch
from
fix/333-multipart-post-parameters
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df2dffb
Include parameters in multipart POST request
fluiddot 8477576
Add body parts to multipartPOST request
fluiddot 648bb7f
Merge branch 'develop' into fix/333-multipart-post-parameters
fluiddot d5c505c
Update WordPressKit/PostServiceRemoteREST.m
fluiddot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking for one of the use cases for https://developer.wordpress.com/docs/api/1.1/post/sites/%24site/media/new/,
I think treating
parametersasQuery Parametersand adding another function parameter specifically forRequest Parameterscould be beneficial in case we also want to sendQuery Parametersnext toRequest Parametersin the future.One other option could be to change the type of
parametersto[String: String]?instead of checking for types here.Yet another option could be adding another parameter to the method that takes a function like
multipartFormData -> Voidand the caller can deal with how to append those?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ceyhun for the feedback!
I though about this option but I wasn't sure if having both could be confusing. In regular POST requests we only have
parametersand they're considered as theRequest Parameters, in that caseQuery Parametersshould be previously added to the URL.Yeah that would prevent having to check the types as I did, I included
Inttype because I saw a couple of cases where there were arguments of that type. In any case since we're converting them intoStringwhen parsing the value toDatawe could use[String: String]?and let the callers explicitly do the conversion.I think this one is probably the best since it will let the caller to include more complex values than primitives. The downside is that callers would have to do the parsing to
Databut I think that's expected since it's a multipart POST request.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to apply option 3 but unfortunately the class
MultipartFormDatathat Alamofire provides is not compatible withObjCand the places where this type of request is being used areObjC, however this gave me an idea.The idea was to unify the
Request Parametersinto one argument, including the file parts which in the end are also body parts. Following this I created a new argument namedbodyPartsthat is an array ofBodyPart, a new class I added (based on the previous oneFilePart) but more generic that represents a body part of the multipartPOST requests.I'd appreciate feedback of this change since I'm unaware of the implications of such a refactor, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great idea! But there appears to be a
BodyPartclass in Alamofire as well. Should we maybe rename this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'm not familiar of class name conflicts on iOS but yeah if it could produce it let's rename it. I was thinking to use
FormPartorRequestPart🤔 .There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
FormPartcould be better since it's used inMultipartFormData.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah makes sense, I'll rename it then, thanks!