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