Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hello Team ,
I have a "App folder" created and I try to list all the files inside the folder . From the response received , I grep for a particular zip file and download the zip file using "/2/files/download_zip" endpoint . It does download the zip file but when I try to unzip it using "unzip <filename>" , it doesnt unzip , the file is corrupted . When I download the zip file manually and try to unzip it , it works fine . So the issue is not with the file . Kindly help . Following is the error :
note: Assessor-4.31-cli-linux.zip may be a plain executable, not an archive
unzip: cannot find zipfile directory in one of Assessor-4.31-cli-linux.zip or
Assessor-4.31-cli-linux.zip.zip, and cannot find Assessor-4.31-cli-linux.zip.ZIP, period.
This is the code I'm using : I also try to compare all the files and retrieve the latest version for download
dropboxFolderPath=""
localDestination="/usr/orabkup/CISCAT"
apiUrl="https://api.dropboxapi.com/2/files/list_folder"
# Set the headers for the API request
headers=(
"Authorization: Bearer $dropboxToken"
"Content-Type: application/json"
)
# Specify the folder path in the Dropbox API request body
body="{\"path\": \"$dropboxFolderPath\", \"recursive\": true}"
# Make the API request to list the files in the folder
response=$(curl -X POST -H "${headers[0]}" -H "${headers[1]}" --data "$body" "$apiUrl")
echo $response
# Check if the API request was successful
if [[ $response ]]; then
# Filter the files based on the pattern "*Assessor*linux*.zip"
files=$(echo "$response" | grep -o '"name": "[^"]*"' | sed 's/"name": "//;s/"$//' | grep "Assessor.*linux.*\.zip")
# echo $files
latestVersion=""
latestFilename=""
for filename in $files; do
version=$(echo "$filename" | grep -oP '(?<=-)[\d\.]+(?=[-\.])')
if [[ -z $latestVersion ]]; then
latestVersion=$version
latestFilename=$filename
elif [[ $(printf "%s\n%s" "$version" "$latestVersion" | sort -V | tail -n 1) == $version ]]; then
latestVersion=$version
latestFilename=$filename
fi
done
#echo $latestFilename
if [[ -n $latestFilename ]]; then
# Download the file with the latest version
localPath="$localDestination/$latestFilename"
downloadUrl="https://content.dropboxapi.com/2/files/download_zip"
downloadHeaders=(
"Authorization: Bearer $dropboxToken"
"Dropbox-API-Arg: {\"path\": \"/$dropboxFolderPath/$latestFilename\"}"
)
curl -s -X POST -H "${downloadHeaders[0]}" -H "${downloadHeaders[1]}" -o "$localPath" "$downloadUrl"
Thank you
The /2/files/download_zip endpoint is only meant for downloading folders from Dropbox, not files. (Dropbox zips the folder into a zip file on the fly for that.) To download a file (whether the file is a .zip file or not), you would use the /2/files/download endpoint instead.
Also, it looks like your `path` value might be malformed regardless, at least based on the code you shared here, since you're building it as `"/$dropboxFolderPath/$latestFilename"`, and you're setting `dropboxFolderPath` as `dropboxFolderPath=""`, so `"/$dropboxFolderPath/$latestFilename"`, would contain an empty path component as the first path component.
In any case, you should also check the status code of the HTTPS response to see if the call succeeded or failed, and only save the data if the call succeeded. If it failed, you might just be saving the error message instead of the file data.
And for debugging issues, you can use the "-v" flag on curl to enable verbose output.
@nive wrote:... It does download the zip file ...
Hi @nive,
Wow...😯 Really? That would be really surprising. 🤔
@nive wrote:... I grep for a particular zip file and download the zip file using "/2/files/download_zip" endpoint . ...
If you take a look on /2/files/download_zip's documentation:
Download a folder from the user's Dropbox, as a zip file. The folder must be less than 20 GB in size and any single file within must be less than 4 GB in size. The resulting zip must have fewer than 10,000 total file and folder entries, including the top level folder. The input cannot be a single file. ...
Why do you decided that you need to use exactly this API access point? Let's recall the zip file is a... file! It's NOT a folder. 🙂
By the way, when you say that particular thing is done ("It does download the zip file" in particular), better check what has been done actually and is there some error in meantime! Actually you don't check for error at all and that's where you confusion comes from. 😉 You got - "error_summary": "path/not_folder/.." for sure. Does this text look like a zip file content? 😁
Hope this clarifies matter and gives direction.
PS: By default curl doesn't report server side errors as a returned status. To make curl respond with corresponding status (that you can check) use -f flag.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!