Welcome Guest, Not a member yet? Register   Sign In
CURLRequest multipart File - nothing send
#1

(This post was last modified: 02-01-2020, 08:17 AM by Tysonpower.)

Hello everybody,

i currently working on a function in a Project of mine where i need to send a file over POST to an API.

I used CURLRequest for a POST and GET Api before what works great, but i can't get the multipart File Upload working.
I tested it with webhook.site to see what is send. The header is set to multipart, so the multipart option seems to work like it is described in the docs. But the file size is 0 byte and the form parameters are also missing.

Did i just miss something or is there a bug? Here is my Codesnippet, the File is created and is not empty, the path variable also has the right path in it. HTTP Response is 200 OK.

Code:
$client = \Config\Services::curlrequest();

// create temp file to upload
$tmpfname = tempnam(sys_get_temp_dir(), 'temp_file');

$handle = fopen($tmpfname, "w");
fwrite($handle, 'test data u know?');
fclose($handle);

// fill post data
$post_data = [
   'para' => 'testparam',
   'file' => new \CURLFile($tmpfname)
   ];

$response = $client->request('POST', 'https://webhook.site/randomiduknow', [
   'multipart' => $post_data
   ]);

Hope someone has an idea so that i don't have to use curl on it's own Smile

regards,
Manuel
Reply


Messages In This Thread
CURLRequest multipart File - nothing send - by Tysonpower - 02-01-2020, 07:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB