Jump to content

what's wrong? base64_encode API gallery NO_IMAGE


Constructor

Recommended Posts

$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

image.thumb.png.ec7cd3a7536bd68a880324f15550f7a7.png

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.

Link to comment
Share on other sites

8 hours ago, IPCommerceFan said:

Try replacing this:

$data = file_get_contents($path);

with this:

$data = urlencode(file_get_contents($path));

Reference:
 

 

image.thumb.png.47612ba9d3e9dcfb3be8fe2ce1b2c0fb.png

/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)

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...