M
M
matveyboyko2019-04-18 16:27:48
API
matveyboyko, 2019-04-18 16:27:48

How to upload a file to disk in Bitrix24 using the API?

I read and tried a lot of examples of uploading and attaching a file to a task from the documentation, but the result was not achieved.
Using the CFile::SaveFile method, the file is loaded, an ID is assigned to it, and, according to the documentation, using

if (CModule::IncludeModule("tasks"))
{
    $ID = 1;
    $arFiles = array(102, 34, 5);
    CTasks::AddFiles($ID, $arFiles);
}

it must be attached to the task. This option did not work for me, because, apparently, the wrong ID is obtained with CFile::SaveFile.
I tried to manually upload the file to the Disk, take the ID from there, and then in this way:
if (CModule::IncludeModule('disk') && CModule::IncludeModule('tasks')){
   $oTask = new CTaskItem($task_id, $user_id);
   $arFields = array(
      "UF_TASK_WEBDAV_FILES"   => array("n".$disk_file_id)
   );
   try
   {
      if ( ! $oTask->update($arFields) )
         throw new TasksException();      
   }
   catch (TasksException $e)
   {
      print_r($e);
      return;
   }
}

the file was successfully attached.
Now it remains to solve the problem of how to upload a file to Disk using the API.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question