Upload base64 encode using rest api

Are you looking for help?

@sergey.kuk , you ask me for new topic :slight_smile:

Backendless Version 3/5

Client SDK REST

Please describe the expected behavior of the issue, starting from the first action.

  1. I have an image/png base64 encode string
  2. I am uploading the base 64 encode from byte array using rest api
  3. the file content in the server get an json array with byte array

Actual Behavior

  1. using the put method with the same content type - Content-Type: multipart/form-data
    2.getting this error , once send as an base64 encode , once array , once plain text

the result as follow :

Please provide a simple code that could be run in a new clean app and reproduce the issue.

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, ‘http://api.backendless.com/519D3627-53FA-5FD5-FF77-E3BB5B7F6900/FD09A50B-5126-6998-FFF6-2F14302CD300/files/binary/testfolder/save1.png?overwrite=true’);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘PUT’);

curl_setopt($ch, CURLOPT_POSTFIELDS, $image);

$headers = array();
$headers = ‘Content-Type: multipart/form-data’;
$headers = ‘Application-Type: REST’;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo ‘Error:’ . curl_error($ch);
}
curl_close($ch);

echo $result;

@tomer_moas You should change content-type to text/plain
Use the following example, but put your app id and api key:

curl -X PUT \
  https://api.backendless.com/<your-app-id>/<your-api-key>/files/binary/split.png \
  -H 'Content-Type: text/plain' \
  -d 'iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAADO1JREFUeJzt3XmMnVUZx/HvTFuY0haQlrJJqYKsKktBloBWwhIEiSEomyRGYmQV/hDiAlIBo3EviBopopGyIxEUQYwYDFAUoaxFQGgFUShCpVS7j3+c1g7TuTP3vvd5nvMuv09y/pt5znLPc+9973vec0BERERERERERERERERERERERERERERERESqpCd3AxrkAGDHgHpuBJYE1CNiahbQH1C2i+pQE/TmbkCDjKpZPY2gBIkzOqgeJYghJUicqASJ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gT1alyDWZAO+j2K8gZStXY3/Dazda332uUunmmkyAM8j/InZTPG94nVSC/nVT5tP9NVnj9QDXkv/FLFIWk5bSePpBCfpZpFhdkwlpSfyT5H9ROy0f8xiMQTYE/pSpf90Uy2syAXZh+EWNZSszfYZhSFNJz4rk7nO7xeOaTIDjyf/itlPuJ/6G14eM2u5dtAjR2WXkf5GHKwvJd7DlxW22MVdZjBYhuiu6qDGirCatMM6l6KLGqKJFiEG6WdToWb7k2ek2dbOo0bNoEWKww+l+4aBluYPy3PA6gO4XNVoWLULMZAb5X/x+0pKYsm2edg75x6UfLULMahRpCXrOCbCctCSmbHpIT13mHJvc12RC/kWNZ/h3sbCNSc/x5xqbC/y7KO3YlzyLGq+h/De83k2eRY23U55rMgHOJHYCPEl19v/9OLFjs4C0tY+USOSixjdJS1+qJGpRoxYhlljUosbjozpkKGpRoxYhltyu+C5qvCyuK+am4ruocTblvyYT4AR8JsAcqn/D60h8xuYJtAixUr6H7QR4lbTEpQ4uwXZsIh4ME2MbAg9gMwFWk5a21MUo4LfYJUjEg2HiwGpR44zgdkeYjM2ixsgHw8RBt4sa7yS949ZRt4satQixJmZQbAK8QPkWIVoruqgx54NhYqzIosblpKPg6q6HtAt7p9dkWoRYM5NInwjtToKz8jQzi04XNZbhwTBxsB/tLWq8jubd8HoP8B9GHptfo0WItXYWw0+AeaS9b5voZIYfGy1CbIDhFjUuIe1522Q/pPU1WRkfDBMH40mfFIMnwYk5G1USfcCDrD82p+dslMTblbc+SHR53uaUylTeuqhRixAb6ijgEeAnpKUpss4HgYdIh/VU5cEwERERERERERERERERERERERERERERERERERERERERERHJ5X9I0SfhrEGx/QAAAABJRU5ErkJggg=='

And you will see uploaded file https://take.ms/mxGPM

hi @sergey.kuk

I copied your base64…
to my request and the file content broken , I change it to txt and that the content :
maybe im doing something wrong in my php curl request.
I know its not your job to fixed php , maybe still I can’t get help , I 3 days trying to find

online the problem

Hello @tomer_moas

try this one:

<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "http://api.backendless.com/APP_ID/API_KEY/files/binary/testFolder/save1.png?overwrite=true",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "PUT",
  CURLOPT_POSTFIELDS =>"iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEwAACxMBAJqcGAAADO1JREFUeJzt3XmMnVUZx/HvTFuY0haQlrJJqYKsKktBloBWwhIEiSEomyRGYmQV/hDiAlIBo3EviBopopGyIxEUQYwYDFAUoaxFQGgFUShCpVS7j3+c1g7TuTP3vvd5nvMuv09y/pt5znLPc+9973vec0BERERERERERERERERERERERERERERERESqpCd3AxrkAGDHgHpuBJYE1CNiahbQH1C2i+pQE/TmbkCDjKpZPY2gBIkzOqgeJYghJUicqASJqqcRlCBx9BWrgpQgcfQVq4KUIHHGBNWzQVA9jaAEiTMuqJ6NguppBCVInKgEiaqnEZQgcaIm7vigehpBCRJHnyAVpASJowSpICVInKivPhOC6mkEJUiMjYCxQXVtFlRPIyhBYkwMrGtSYF21pwSJEZkgkXXVnhIkRuS7uj5BDClBYugrVkUpQWJsFVjXloF11Z4SJMa2gXVNADYJrK/WlCAxIhMkR321pQSJoQSpKCVIDCVIRSlB/PURe5EO8M7g+mpLCeJvB+LHeafg+mpLCeJv54bUWUtKEH85Juv2xD0DX2tKEH85EmQMug4xoQTxt0emenfPVG+tKEF8jQN2yVT3tEz11ooSxNce5BvjvTPVWytKEF8538X3Que/dE0J4mv/jHVvin7u7ZoSxE8PMD1zG3LXX3lKED87kv/ZjOmZ6688JYif6bkbQGqDrkO6oATxc0TuBgCTgT1zN6LKlCA+xgKH5m7EGkfnbkCVKUF8HEx5jiF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blvyYT4AR8JsAcqn/D60h8xuYJtAixUr6H7QR4lbTEpQ4uwXZsIh4ME2MbAg9gMwFWk5a21MUo4LfYJUjEg2HiwGpR44zgdkeYjM2ixsgHw8RBt4sa7yS949ZRt4satQixJmZQbAK8QPkWIVoruqgx54NhYqzIosblpKPg6q6HtAt7p9dkWoRYM5NInwjtToKz8jQzi04XNZbhwTBxsB/tLWq8jubd8HoP8B9GHptfo0WItXYWw0+AeaS9b5voZIYfGy1CbIDhFjUuIe1522Q/pPU1WRkfDBMH40mfFIMnwYk5G1USfcCDrD82p+dslMTblbc+SHR53uaUylTeuqhRixAb6ijgEeAnpKUpss4HgYdIh/VU5cEwERERERERERERERERERERERERERERERERERERERERERHJ5X9I0SfhrEGx/QAAAABJRU5ErkJggg==",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: text/plain"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

for me it works well

Regards, Vlad

hiiii , thanks a lot . :slight_smile:
its working for me …
I will implement that in my code.
and then will post the result and the problem I had.

thanks :slight_smile: