The Dropbox connector can be used to read Dropbox files from within your scripts in Peliqan. For example, you can implement a file sync from Dropbox to a target API (e.g. an ERP or CRM or Project management tool).
Connect Dropbox
In Peliqan, go to Connections, click “Add connection”, and select Dropbox from the list.
Complete the authorization flow by granting the Peliqan app access to your Dropbox account.
List items in a Dropbox folder
Here’s an example on how to get a list of items (folders, files) from a given path:
dropbox_api = pq.connect("Dropbox")
path = "" # Root folder
items = dropbox_api.get("files", {"path": path})
for item in items:
if item[".tag"] == "file":
st.text(item["name"] + " is a file"
elif item[".tag"] == "folder":
st.text(item["name"] + " is a folder"Download a file from Dropbox
Here’s an example on how to download a file from Dropbox as a base64 encoded string:
dropbox_api = pq.connect("Dropbox")
content = dropbox_api.get("downloadfile", {"path": "/myfile.pdf"})
st.write(content["base64"])Upload a file to Dropbox
Here’s an example on how to upload a file to Dropbox:
dropbox_api = pq.connect("Dropbox")
file_content_base64 = base64.b64encode(file_bytes).decode("ascii")
uploadfile_params = {
"path": "/myfile.pdf",
"content_type": "application/octet-stream",
"file_content_base64": file_content_base64
}
result = dropbox_api.add('uploadfile', uploadfile_params)
st.write(result)Script templates
File explorer with file sync to a target API
This example script allows the user to select a folder in Dropbox. The script can be scheduled and will sync all files in the folder to a target API (e.g. an ERP or CRM or Project management tool). The script keeps track if which files are already synced and will sync each file only once.