We Want to Hear From You! What Do You Want to See on the Community? Tell us here!
Forum Discussion
lucaortis
3 years agoExplorer | Level 4
Can't delete files with powershell
function DropBox-FileDelete {
Param (
[Parameter(Mandatory=$true)]
[string]$SourceFilePath
)
$DropBoxAccessToken = TOKEN HERE
$testFile = $SourceFilePath
$TargetFilePath="/$testFile"
$arg = '{"path": "' + $TargetFilePath + '"}'
$authorization = "Bearer " + $DropBoxAccessToken
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", $authorization)
$headers.Add("Content-Type", 'application/json')
try {
$result = Invoke-RestMethod -Uri https://api.dropboxapi.com/2/files/delete_v2 -Method Post -Headers $headers -Body $arg
}
catch {
$result = $_.Exception.Response.GetResponseStream()
$reader = New-Object System.IO.StreamReader($result)
$reader.BaseStream.Position = 0
$reader.DiscardBufferedData()
$responseBody = $reader.ReadToEnd();
}
Write-Output $responseBody
}
DropBox-FileDelete "/Applicazioni/Costumer Manager Files/Ore.txt"
Hello. I just started using the API and I ran into this issue:
I can upload files, I can download files but I cannot delete them.
What am I missing here?
It seems a path problem, but to me the path is fine.
If the path was wrong, then I would not be able to upload or download, instead, I can download and upload just fine.
Response body:
{"error_summary": "path_lookup/malformed_path/", "error": {".tag": "path_lookup", "path_lookup": {".tag": "malformed_path"}}}
3 Replies
- Здравко3 years agoLegendary | Level 20
lucaortis wrote:...
It seems a path problem, but to me the path is fine.
If the path was wrong, then I would not be able to upload or download, instead, I can download and upload just fine....
Hi lucaortis,
You haven't posted the code responsible for upload and download. Are you using in the path there double leading slashes too? 🤔😁😉
Hope this gives direction.
- Greg-DB3 years ago
Dropbox Community Moderator
lucaortis As Здравко pointed out, you have a double leading slash, which is not a valid path format.
Specifically, you're supplying the path "/Applicazioni/Costumer Manager Files/Ore.txt", but then are adding an extra leading slash when you format it with your code:
$TargetFilePath="/$testFile"
- lucaortis3 years agoExplorer | Level 4
I found this very confusing but I managed to solve it like this:
$testFile = Split-Path $SourceFilePath -leaf $TargetFilePath="/$testFile" $arg = '{"path": "' + $TargetFilePath + '"}'
I know it works, but I'm really confused on how the path itself works.
Upload and download code to format PATH are now the same as this.
Thank you!!
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.6,031 PostsLatest Activity: 10 hours ago
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or 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!