M.O.S. Studios Posted Wednesday at 03:42 AM Share Posted Wednesday at 03:42 AM (edited) Can anyone make heads or tales of this? I am playing around with pCloud. The Pcloud file upload documentation is kinda vague. they don't explain where or how to attach the file, just how to name it, and where to put it. They even have instructions on how to send it as binaries. but that is also kind of vague. Can someone see what I am missing? This code is supposed to take a string, create a temp file, and then upload it. at the moment, it uploads a file with the right file name, but only contains two dashes $uploadPath = 'uploadpath'; $accessToken = AccessToken; $product_data = fopen('php://memory', 'r+'); fputs($product_data, 'content string'); rewind($product_data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.pcloud.com/uploadfile' ); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, array('filename'=>'test.csv', 'data'=>$product_data)); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data', 'Authorization: Bearer '.$accessToken)); $result = curl_exec($ch); var_export(curl_error($ch)); var_export($result); curl_close($ch); Edited Wednesday at 04:05 AM by M.O.S. Studios Quote Link to comment https://forums.phpfreaks.com/topic/327814-pcloud-abd-curl/ Share on other sites More sharing options...
Solution M.O.S. Studios Posted Thursday at 12:32 AM Author Solution Share Posted Thursday at 12:32 AM So, after giving up on the documentation I gave postman.com a gander. All the parameters are supposed to be sent within the URL, and the file as the only information in the post field. They also allow you to send plain text, and they will encode it for you. So here is what I did: $uploadPath = str_replace("/".basename($args['uploadPath']), '', $args['uploadPath']); $accessToken = getPcloudToken(); $query = array('filename'=>'file.csv', 'nopartial'=>'1', 'path'=> $uploadPath); $product_data = $args['product_data']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.pcloud.com/uploadfile?'.http_build_query($query)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt($ch, CURLOPT_POST, 1 ); curl_setopt($ch, CURLOPT_POSTFIELDS, $product_data); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/plain', 'Authorization: Bearer '.$accessToken)); curl_exec($ch); curl_close($ch); I was able to take the whole temp file creation out. so that was nice Quote Link to comment https://forums.phpfreaks.com/topic/327814-pcloud-abd-curl/#findComment-1653936 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.