Upload API

Curl can be used to upload files to the platform, these files can then be retrieved in the platform Filebrowser: http://localhost:1912/filebrowser/

Create a folder with Curl


export FOLDER_NAME=test_folder

curl -X POST http://localhost:1912/filebrowser/api/resource/$FOLDER_NAME

Upload file with Curl


export FILE_PATH=/tmp/example.png
export REMOTE_FILENAME=example.png

curl -X POST \
     -H "Content-Type: multipart/form-data" \
     -F "data=@${FILE_PATH}" \
     http://localhost:1912/filebrowser/api/resource/$REMOTE_FILENAME

Delete a file or a folder with Curl

By default, nginx will not allow files and foldes to be deleted from outside the filebrowser UI.

If you need to modify this behavior, you can comment the line returning a 403 Not Allowed error message from nginx config in code/${ARCH}/config/nginx/nginx.conf in the filebrowser location:


location ~ /filebrowser {

  valid_referers ~\/filebrowser\/files\/ ~\/annotations\/;

  if ($invalid_referer) {
    set $check_referer_delete invalid_referer;
  }

  if ($request_method = DELETE) {
    set $check_referer_delete "${check_referer_delete}_delete";
  }

  if ($check_referer_delete = "invalid_referer_delete") {

    # ####
    # Comment the following line to allow file/folder delete from outside filebrowser
    return 403;
    # ####

  }

  proxy_pass http://filebrowser;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
}

Then you can use Curl to delete files and folders:


export FOLDER_NAME=test_folder
export FILE_NAME=example.png

curl -X DELETE http://localhost:1912/filebrowser/api/resource/$FOLDER_NAME/$FILE_NAME
curl -X DELETE http://localhost:1912/filebrowser/api/resource/$FOLDER_NAME

Related