Constructor Posted May 29, 2019 Posted May 29, 2019 $communityUrl = '...'; $apiKey = '...'; $endpoint = '/gallery/images'; $curl = curl_init( $communityUrl . 'api' . $endpoint ); $file_desc = '<p>Description</p>'; //img $path = '2.png'; $data = file_get_contents($path); $base64 = base64_encode($data); var_dump($base64); // Settings $curl_post_data = array( 'category' => 1, 'author' => 1, 'caption' => 'REST POST', 'description' => $file_desc, 'filename' => '1.jpg', 'image' => $base64, 'hidden' => 1, ); // Prepare data for cURL POST $curl_post_data = urldecode(http_build_query($curl_post_data)); // POST Data curl_setopt_array( $curl, array( CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPAUTH => CURLAUTH_BASIC, CURLOPT_USERPWD => "{$apiKey}:", CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $curl_post_data ) ); // Get Response $response = curl_exec( $curl ); // Get info array $response = json_decode($response); var_dump($response); Quote Any image that I try to upload produces such an error and only 1 time with 1 very small img of 64x64 through the online service img to base64_encode I could.
IPCommerceFan Posted May 29, 2019 Posted May 29, 2019 Try replacing this: $data = file_get_contents($path); with this: $data = urlencode(file_get_contents($path)); Reference:
Constructor Posted May 29, 2019 Author Posted May 29, 2019 8 hours ago, IPCommerceFan said: Try replacing this: $data = file_get_contents($path); with this: $data = urlencode(file_get_contents($path)); Reference: /var/www/html/test/api.php:51:string 'JTg5UE5HJTBEJTBBJTFBJTBBJTAwJTAwJTAwJTBESUhEUiUwMCUwMCUwMSU5MCUwMCUwMCUwMSU5MCUwOCUwNiUwMCUwMCUwMCU4MCVCRjYlQ0MlMDAlMDAlMDAlMDlwSFlzJTAwJTAwJTBCJTEzJTAwJTAwJTBCJTEzJTAxJTAwJTlBJTlDJTE4JTAwJTAwOCUyNmlUWHRYTUwlM0Fjb20uYWRvYmUueG1wJTAwJTAwJTAwJTAwJTAwJTNDJTNGeHBhY2tldCtiZWdpbiUzRCUyMiVFRiVCQiVCRiUyMitpZCUzRCUyMlc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCUyMiUzRiUzRSUwQSUzQ3glM0F4bXBtZXRhK3htbG5zJTNBeCUzRCUyMmFkb2JlJTNBbnMlM0FtZXRhJTJGJTIyK3glM0F4bXB0ayUzRCUyMkFkb2JlK1hNUCtDb3JlKzUuNi1jMTExKzc5LjE1ODMyNSUyQysyMDE1JTJGMDkl'... (length=78584) /var/www/html/test/api.php:82: object(stdClass)[3] public 'errorCode' => string '1G316/6' (length=7) public 'errorMessage' => string 'NO_IMAGE' (length=8)
newbie LAC Posted May 30, 2019 Posted May 30, 2019 The problem in the urldecode $curl_post_data = urldecode(http_build_query($curl_post_data));
Constructor Posted May 30, 2019 Author Posted May 30, 2019 23 minutes ago, newbie LAC said: The problem in the urldecode $curl_post_data = urldecode(http_build_query($curl_post_data)); I have no ideas
Constructor Posted May 30, 2019 Author Posted May 30, 2019 7 minutes ago, newbie LAC said: Remove urldecode Thank you.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.