Tutorial 1: Get your files to the cloud
On this tutorial we will upload, download and delete files. We will also create folders and learn how to remove all the items from our workspace. Let's start by creating a test folder
Step 1: Get Token
curl -L -X POST 'https://api.sherpalive.com/v2/authenticate' \
-H "X-Sherpa-apikey: XXXX-SHERPA-DELIVERED-PUBLIC-APIKEY-XXXX" \
-H "X-Sherpa-timestamp: XXX-TIMESTAMP-XXX" \
-H "X-Sherpa-nonce: XXXX-SHERPA-RANDOM-UUID-XXXX" \
-H "X-Sherpa-hmac: XXXX-SHERPA-HMAC-SIGNATURE-XXXX" \
Header Response
Authorization :XXXX-SHERPA-TOKEN-XXXX
Step 2: Create a folder
curl -L -X PUT 'https://api.sherpalive.com/v2/storage/folder/testing' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
{"folder":"test-folder"}
We just created our first folder!
Step 3: List folders
We can easily get a list of the folders that we have:
curl -L -X GET 'https://api.sherpalive.com/v2/storage/folder/list' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
The answer will be
["testing"]
Step 4: Upload a file
We want to upload a file to our newly created folder. Let's first get a sample file from the following link. For the sake of simplicity, we will assume that the file has been downloaded to the /tmp
folder. We will upload it to the folder that we just created:
curl -L -X POST 'https://api.sherpalive.com/v2/storage/file/upload/testing' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Content-Type: multipart/form-data'
-H 'Time-Zone: Europe/Madrid' \
-F 'file=@/tmp/Donors.csv'
We get a confirmation answer:
{
"file": "Donors.csv",
"folder": "testing"
}
Step 5: Check our progress so far
We can easily verify if a file named Donors.csv
exists in the testing
folder.
curl -L -X GET 'https://api.sherpalive.com/v2/storage/file/exists/testing/Donors.csv' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Time-Zone: Europe/Madrid'
The answer will be true
. We may also want to obtain a list of all the files contained in the testing
folder:
curl -L -X GET 'https://api.sherpalive.com/v2/storage/files/list/testing' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Time-Zone: Europe/Madrid'
We will get a list with one element, holding information about the file we just uploaded: The name, the size (in bytes) and the timestamp of the last modification:
[
{
"name": "Donors.csv",
"size": 117446,
"lastModified": 1604911035000
}
]
Step 6: Delete the file
Let's undo our work. First, we can delete a specific file, namely Donors.csv
.
curl -L -X DELETE 'https://api.sherpalive.com/v2/storage/file/delete/testing/Donors.csv' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Time-Zone: Europe/Madrid'
Done! We can send the same cURL command several times, the result will be the same: The file does not longer exist in our workspace.
Step 7: Delete the folder
We can also delete folders, wether they are empty or not. The following command will do the work:
curl -L -X DELETE 'https://api.sherpalive.com/v2/storage/folder/delete/testing' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Time-Zone: Europe/Madrid'
Step 8: Work in the root folder
We may want to upload a file without specifying a target folder.
curl -L -X POST 'https://api.sherpalive.com/v2/storage/file/upload' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Content-Type: multipart/form-data'
-H 'Time-Zone: Europe/Madrid' \
-F 'file=@/tmp/Donors.csv'
The file has been uploaded to the root folder:
{"file":"Donors.csv"}
Let's check the files that we have stored in the root folder:
curl -L -X GET 'https://api.sherpalive.com/v2/storage/files/list' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Time-Zone: Europe/Madrid'
We get the file we just uploaded:
[
{
"name": "Donors.csv",
"size": 117446,
"lastModified": 1604919035000
}
]
Optionally, you may upload the file again and get a file list once more. You will observe that the answer is the same, the only thing that changes is the lastModified field.
Step 9: Clean up the house
Eventually it may come handy to clear the whole workspace. In other words, we may want to erase everything. This operation has two steps. First, we have to obtain a deletion token:
curl -L -X GET 'https://api.sherpalive.com/v2/storage/clear' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Time-Zone: Europe/Madrid'
The endpoint returns a temporary token:
aa0c4826-d119-4aa5-9a4a-3aa437d66e00
Now, we have a short time window to use it. Otherwise, it will expire. Let's delete everything:
curl -L -X GET 'https://api.sherpalive.com/v2/storage/clear/aa0c4826-d119-4aa5-9a4a-3aa437d66e00' \
-H "Authorization: Bearer XXXX-SHERPA-TOKEN-XXXX" \
-H 'Accept-Language: es-ES' \
-H 'Time-Zone: Europe/Madrid'
The user workspace has been emptied. You may confirm it by using the file and/or folder listing operations described above.