Documentation

disk.storage.uploadfile

Description

disk.storage.uploadfile

Uploads a new file to the storage root.

In case of success, it returns a structure similar to that of disk.file.get.

Response example:

"result": {
    "ID": "10",
    "NAME": "2511.jpg",
    "CODE": null,
    "STORAGE_ID": "4",
    "TYPE": "file",
    "PARENT_ID": "8",
    "DELETED_TYPE": "0",
    "CREATE_TIME": "2015-04-24T10:41:51+03:00",
    "UPDATE_TIME": "2015-04-24T15:52:43+03:00",
    "DELETE_TIME": null,
    "CREATED_BY": "1",
    "UPDATED_BY": "1",
    "DELETED_BY": "0",
    "DOWNLOAD_URL": "https://test.bitrix24.com/disk/downloadFile/10/?&ncc=1&filename=2511.jpg&auth=******",
    "DETAIL_URL": "https://test.bitrix24.com/workgroups/group/3/disk/file/2511.jpg"
}

Parameters

Parameter Description
id Storage ID.
fileContent Similar to 'DETAIL_PICTURE' in the example Files Processing.
data An array describing the file. Mandatory field NAME contains the name of the new file.
generateUniqueName Optional, false by default. When true, uploaded filename will be uniqualized by adding the suffix (1), (2) Example:

avatar (1).jpg
avatar (2).jpg
and etc.
rights Optional, empty array by default. Array with access permissions for uploaded file.

Example

Please be advised, the list of available `TASK_ID` identifiers for setting access permissions can be retrieved by REST method disk.rights.getTasks.

BX24.callMethod(
        "disk.storage.uploadFile",
        {
            id: 4,
            data: {
                NAME: "avatar.jpg"
            },
            fileContent: document.getElementById('test_file_input'),
			generateUniqueName: true,
			rights: [
				{
					TASK_ID: 42,
					ACCESS_CODE: 'U35' //access for user with ID=35. You can use https://training.bitrix24.com/rest_help/general/access_name.php to get name for access type
                },
				{
					TASK_ID: 38,
					ACCESS_CODE: 'U2' //access for user with ID=35. You can use https://training.bitrix24.com/rest_help/general/access_name.php to get name for access type
                }
            ]
        },
        function (result)
        {
            if (result.error())
                console.error(result.error());
            else
                console.dir(result.data());
        }
);


© «Bitrix24», 2001-2024