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

Post files does not work (php7.1) #46

Closed
danielsetreus opened this issue Sep 14, 2017 · 3 comments · Fixed by #55
Closed

Post files does not work (php7.1) #46

danielsetreus opened this issue Sep 14, 2017 · 3 comments · Fixed by #55

Comments

@danielsetreus
Copy link

danielsetreus commented Sep 14, 2017

POSTing files does not work as intended.

This is what I'd like to do:

$file = new \CURLFile($filePath, mime_content_type($filePath), 'file_post_name');
$data = array(
	'mode' => 'import',
	'file' => $file,
);
$this->curl->setHeader('Accept', 'application/json');
$this->curl->setHeader('Content-Type', 'application/json');
$this->curl->post('http://example.com', $data);
$this->curl->close();

However what is posted is a string representation of the data, including the CURLFile instance, not the actual file. I.e:

mode=import&file%5Bname%5D=path/to/file/&file%5Bmime%5D=mime_type_of_file&file%5Bpostname%5D=file_post_name

This is due to the preparePayload method - that runs http_build_query on the data. If I remove those lines everything works as expected.

The library should include a way to skip http_build_query, or a special method for adding a file to the posted data.

Thanks

@worka
Copy link

worka commented Nov 7, 2017

Faced the same problem

@nadar
Copy link
Member

nadar commented Mar 28, 2018

@danielsetreus We could isolate the array keys which are an instanceof \CURLFile and add them after processing the http_build_query() data?

@nadar nadar mentioned this issue Mar 28, 2018
nadar added a commit to nadar/curl that referenced this issue Nov 14, 2018
This is not tested, but we are facing the same problem with CurlFile Uploads (php-mod#46) - This *should* do the trick.
This was referenced Nov 14, 2018
@nadar
Copy link
Member

nadar commented Nov 15, 2018

@danielsetreus https://github.com/php-mod/curl/pull/53/files this should fix the problem - right?

amouhzi pushed a commit that referenced this issue Nov 15, 2018
* CurlFile fix

This is not tested, but we are facing the same problem with CurlFile Uploads (#46) - This *should* do the trick.

* Update README.md
@nadar nadar mentioned this issue Nov 16, 2018
amouhzi pushed a commit that referenced this issue Nov 17, 2018
* CurlFile fix

This is not tested, but we are facing the same problem with CurlFile Uploads (#46) - This *should* do the trick.

* Update README.md

* cs fix
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 a pull request may close this issue.

3 participants