Documentation

Files Processing

The REST methods accept files as a base64 encoded string. Another option is to pass a simple array with the file name as the first array item, and the base64 encoded file data as the second item.

With a pure client application, you can use a FileReader object instance, or pass a reference to a file HTML form element (<input type="file">) as the request field value.

Example

<input type="file" id="testfile"><br />
<span onclick="sendInputFile()">send file from input</span><br />
<span onclick="sendStaticFile()">send static file</span><br />
<script type="text/javascript">
function sendInputFile()
{
   BX24.callMethod('entity.item.add', {
      'ENTITY': 'menu',
      'NAME': Math.random(),
      'DETAIL_PICTURE': document.getElementById('testfile')
   }, function(){
      alert('Finished!');
   });
}
/*
POST https://my.bitrix24.com/rest/entity.item.add.json HTTP/1.1
Host: my.bitrix24.com
Content-Length: 186
Content-Type: text/plain; charset=UTF-8

auth=6a8c365cb010ba42bd5b0f6ae803f47c&ENTITY=menu&NAME=0.2630483947652045&DETAIL_PICTURE[0]=1.gif&DETAIL_PICTURE[1]=R0lGODlhAQABAIAAAP%2F%2F%2FwAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D
*/

function sendStaticFile()
{
   BX24.callMethod('entity.item.add', {
      'ENTITY': 'menu',
      'NAME': '1.gif',
      'DETAIL_PICTURE': ['1.gif', '']
   }, function(){
      alert('Finished!');
   });
}

/*
POST https://my.bitrix24.com/rest/entity.item.add.json HTTP/1.1
Host: my.bitrix24.com
Content-Length: 173
Content-Type: text/plain; charset=UTF-8

auth=6a8c365cb010ba42bd5b0f6ae803f47c&ENTITY=menu&NAME=1.gif&DETAIL_PICTURE[0]=1.gif&DETAIL_PICTURE[1]=R0lGODlhAQABAIAAAP%2F%2F%2FwAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw%3D%3D
*/
</script>

For CRM methods, when adding a picture for a product, instead of

'DETAIL_PICTURE': ['1.gif', 'R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==']

use

"PREVIEW_PICTURE": {"fileData": ["1.gif", "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="]}

Such feature is based on the fact that CRM supports file deletion.



© «Bitrix Inc.», 2001-2021, «Bitrix Inc.», 2021