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

Sending file from a multipart stream #127

Closed
BenoitLeveque opened this issue Jul 3, 2017 · 13 comments
Closed

Sending file from a multipart stream #127

BenoitLeveque opened this issue Jul 3, 2017 · 13 comments

Comments

@BenoitLeveque
Copy link

Q A
Bug? yes
New Feature? no
Version v1.1.0
PHP Version 7.1.5

Actual Behavior

I'm sending some files with a multipart api endpoint, i've followed the doc (http://php-http.readthedocs.io/en/latest/components/multipart-stream-builder.html).

When the profiler is enabled i got this error Error: escapeshellarg(): Input string contains NULL bytes from the CurlCommandFormatter.php

Expected Behavior

no error

Steps to Reproduce

i've followed the documentation here : http://php-http.readthedocs.io/en/latest/components/multipart-stream-builder.html

@Nyholm
Copy link
Member

Nyholm commented Jul 3, 2017

Can you show us some minimal code here and also how you run it?

@fbourigault
Copy link

Also, do you have the involved CurlCommandFormatter.php line?

@BenoitLeveque
Copy link
Author

@fbourigault it's line 42

@BenoitLeveque
Copy link
Author

$request = $this->messageFactory->createRequest('POST', 'api_url');

$data = file_get_contents('foo.jpeg'); // content of the file
$builder = new MultipartStreamBuilder($this->streamFactory);
$builder->addResource('file', $data, ['headers' => ['Content-Type' => $file->getMimeType()], 'filename' => $file->getFilename()]);

$multipartStream = $builder->build();
$boundary = $builder->getBoundary();

$request = $request->withBody($multipartStream);
$request = $request->withHeader('Content-Type', 'multipart/form-data; boundary="'.$boundary.'"');

$response = $this->client->sendRequest($request);

You can put this code inside a symfony controller you should have the error.

@fbourigault
Copy link

@Nyholm
Copy link
Member

Nyholm commented Jul 3, 2017

You are using the CurlClient. It is super fast but also very strict. You have forgotten to add a content-length header. You could use the Content-Length plugin to fix this.

@Nyholm Nyholm closed this as completed Jul 3, 2017
@fbourigault
Copy link

The issue is about using the CurlCommandFormatter so it should happen even when not sending the request. I tried to reproduce it locally but it's working.
Which stream implementation are you using? zend, slim or guzzle?

@Nyholm
Copy link
Member

Nyholm commented Jul 3, 2017

Guzzle psr7.

I tried the code with curl - fail
Tried with guzzle - success
Tried with curl and content-length plugin - success.

But I might be wrong.

@Nyholm Nyholm reopened this Jul 3, 2017
@fbourigault
Copy link

I tried without Symfony and without any client. It worked! I also have the Content-Length header set by the MultipartStreamBuilder.

@BenoitLeveque
Copy link
Author

I'm using guzzle with the symfony integration

here is my configuration :

httplug:
    classes:
        client: Http\Adapter\Guzzle6\Client
        message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
        uri_factory: Http\Message\UriFactory\GuzzleUriFactory
        stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory

each of my clients use factory: 'httplug.factory.guzzle6'

My issue is only present when the profiler is enabled, the ProfilePlugin use a Formatter that use CurlCommandFormatter.

for a quick workaround i've disable the profile plugin and everything work fine

@fbourigault
Copy link

Which plugins are you using?

@BenoitLeveque
Copy link
Author

I'm using 3 plugins:

  • 'httplug.plugin.logger'
  • reference:
    id: 'app.httplug.plugin.base_uri'
  • 'httplug.plugin.authentication.customer'

@joelwurtz
Copy link
Member

This has been fixed in php-http/message#94

Nyholm pushed a commit to Nyholm/httplug that referenced this issue Dec 26, 2019
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

No branches or pull requests

4 participants