We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.

Forum Discussion

Lukag's avatar
Lukag
Collaborator | Level 8
3 months ago

Download file by Api ( Files/download ) , no error no file

I try to dowload a file by a Api .

I have no error and a response with "OK" but i don't see the file.

Have i donwloaded it ? where ? can i set up the local directory where save it ? 

This is my code : ( a big doubt is in content-Type ) 

Dim _command As String
_command = "https://content.dropboxapi.com/2/files/download"

Dim Request As HttpWebRequest
Request = HttpWebRequest.Create(_command)
Request.Method = "POST"
Request.KeepAlive = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 Or SecurityProtocolType.Tls12 Or SecurityProtocolType.Tls11 Or SecurityProtocolType.Tls
Request.ContentType = "application/octet-stream"

Request.UserAgent = "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36"
ServicePointManager.SecurityProtocol = CType(48, SecurityProtocolType) Or CType(192, SecurityProtocolType) Or CType(768, SecurityProtocolType) Or CType(3072, SecurityProtocolType)
Request.AllowAutoRedirect = True


Request.Headers.Add("Authorization", "Bearer " & _token)
Request.Headers.Add("Dropbox-API-Arg", _parameter)
Try
   Dim Response As HttpWebResponse = Request.GetResponse()

Catch ex As WebException
   Using response = CType(ex.Response, HttpWebResponse)
      Using reader = New IO.StreamReader(response.GetResponseStream())
        _error = reader.ReadToEnd()
      End Using
   End Using
Catch ex As Exception
Throw
End Try


  • Lukag wrote:

    I try to dowload a file by a Api .

    I have no error and a response with "OK" but i don't see the file.

    Have i donwloaded it ? where ? can i set up the local directory where save it ? 

    ...


    🙂Your code is Ok. You don't need to change anything. It is not the same about understanding what a network stream is!

    Your file is downloaded (or in process of download at least) but you expect it to be a file on your local file system. Right? Hm... Error! File object and file stream are different things. 😉 Something you don't clearly understand, as seems. You can direct the file stream you received to a file you want, if you want (as seems it is). It's not something mandatory though. That's it. Add whatever you want in your code, if you want; don't expect it comes somewhere from - not clear where. Also, before continue, get familiar with file and file stream (as terms) - what is common and what different.

    Hope this gives direction.

     

    PS: It may be helpful to read here and here.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,877 PostsLatest Activity: 12 months ago
325 Following

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!