Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should support multipart/form-data post requests #565

Closed
pbearne opened this issue Sep 24, 2021 · 3 comments
Closed

should support multipart/form-data post requests #565

pbearne opened this issue Sep 24, 2021 · 3 comments

Comments

@pbearne
Copy link

pbearne commented Sep 24, 2021

Currently, we need to be a bit creative to attach files to a post request

		// Create a boundary. We'll need it as we build the payload.
		$boundary = md5( time() . $ext );

		// End of Line
		$eol = "\r\n";

		// Construct the payload in multipart/form-data format
		$payload  = '';
		$payload .= '--' . $boundary;
		$payload .= $eol;
		$payload .= 'Content-Disposition: form-data; name="submitted_file"; filename="' . $name . '"' . $eol;
		$payload .= 'Content-Type: ' . $format . $eol;
		$payload .= 'Content-Transfer-Encoding: binary' . $eol;
		$payload .= $eol;
		$payload .= $contents;
		$payload .= $eol;
		$payload .= '--' . $boundary . '--';
		$payload .= $eol . $eol;

		// Create args for wp_remote_request
		$args = array(
			'headers' => array(
				'accept'       => 'application/json',
				'content-type' => 'multipart/form-data;boundary=' . $boundary,
			),
		);

		// Call the standard request function and return it.
		return $this->request( $api_method, $params, $http_method, $payload, $args );

I would like to be able to pass an array of mixed objects and have it be handled as multipart form if it is a POST/PUT/OPTIONS/PATCH call

Describe alternatives you've considered

code like above

Additional context (optional)

  • [X ] I am happy to help create a pull request to implement this feature myself.
@jrfnl
Copy link
Member

jrfnl commented Sep 24, 2021

Duplicate of #289 with possible solution via PR #313 ?

@pbearne
Copy link
Author

pbearne commented Sep 27, 2021

yes #313 will work let's close this and get that merged

@jrfnl
Copy link
Member

jrfnl commented Sep 27, 2021

Closing as duplicate of #289

@jrfnl jrfnl closed this as completed Sep 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants