-
Notifications
You must be signed in to change notification settings - Fork 744
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
Create multipart/form-data requests? #985
Comments
You can make it work with this following extra code : if (isset($options['multipart']))
{
$multipartStream = new GuzzleHttp\Psr7\MultipartStream($options['multipart']);
$boundary = $multipartStream->getBoundary();
$options['headers']['content-type'] = "multipart/form-data; boundary={$boundary}";
$options['body'] = $multipartStream;
unset($options['multipart']);
} It is inspired from As stated by this stackoverflow answer, the only keys allowed in Thus in the following code, the $multipart = [];
$multipart[] = [
'name' => "documents[{$key}]",
'contents' => GuzzleHttp\Psr7\Utils::tryFopen($file['tmp_name'], 'r'),
'filename' => $file['name'],
];
$options['multipart'] = $multipart;
$request = $provider->getAuthenticatedRequest($method, $url, $token, $options); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm having issues creating a request with an attached file. Tried a lot of different alternatives but always end up with issues.
Seems like Guzzle in itself handles this, but the oauth2-client is limiting the getAuthenticatedRequest method to using only " Any of "headers", "body", and "protocolVersion".".
Example where it says to not specify form-data:
https://stackoverflow.com/questions/47550801/multiple-files-uploaded-via-guzzle-multipart-form-data-request-are-not-recognize
Another discussion regarding this, I tried following it but cannot get it to work. Guzzle complains about it being an invalid resource type "array" while doing so:
https://stackoverflow.com/questions/58736361/replicate-curl-multipart-form-data-request-with-guzzle-league-oauth2-client?rq=1
Error is thrown in the streamFor method found in Utils.php located in guzzlehttp vendor/psr7/src/Utils.php.
Anyone tried this and got it to work? Any help would be very appreciated.
The text was updated successfully, but these errors were encountered: