Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

veewee
Copy link
Contributor

@veewee veewee commented Nov 9, 2023

Q A
Type feature
BC Break no
Fixed issues

Summary

This PR allows for sending multipart form messages, uploads, mixed multi-parts, ... based on the parts available inside symfony/mime.

use Phpro\HttpTools\Encoding\Json\JsonDecoder;
use Phpro\HttpTools\Encoding\Mime\MultiPartEncoder;
use Phpro\HttpTools\Transport\EncodedTransportFactory;
use Symfony\Component\Mime\Part\DataPart;
use Symfony\Component\Mime\Part\Multipart\FormDataPart;
use Phpro\HttpTools\Request\Request;

$transport = EncodedTransportFactory::create(
    $client,
    $uriBuilder,
    MultiPartEncoder::createWithAutodiscoveredPsrFactories(),
    JsonDecoder::createWithAutodiscoveredPsrFactories()
);

$jsonData = $transport(
    new Request('GET', '/some/file', [], new FormDataPart([
        'name' => 'Jos bos',
        'profile-pic' => DataPart::fromPath('/my-profile-pic.jpg')
    ])),
);

If you wish not to use symfony/mime for this, you could use guzzle/psr7's MultipartStream with the existing StreamEncoder option:

@veewee veewee requested a review from stefliekens November 9, 2023 12:04
@janvernieuwe
Copy link
Contributor

Nice! this will make some (crappy) api's a lot easier to use!

@veewee veewee merged commit 1f2eb53 into phpro:v2.x Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants