Join the Conversation: The Dash Community Is Now Open! ✨🎉
Forum Discussion
Anton U.
10 years agoNew member | Level 1
Dropbox API - Downloading windows exe file
Well, I'm using .net version of Dropbox V2 API with Visual Basic 2015, and I'm trying with it to download an .exe file from my dropbox. So, I do this:
Dim response = Await dbx.files.BeginDownload(path + "/" + file)
filecontainer = Await response.GetContentAsStreamAsync()
Filecontainer is a string. After that, I try to write that string into a created .exe file, and then, that exe file is larger than original. I was thinking it was due to encoding, but it still doesn't work. So, test .exe file is about 940 kB, but a "copy" that's downloaded from dropbox is about 1.7 MB.
Am I doing something wrong or?
3 Replies
Replies have been turned off for this discussion
- Greg-DB10 years ago
Dropbox Community Moderator
Does filecontainer have the length of data you expect? Can you share the rest of the relevant code?
- Steve M.10 years ago
Dropbox Staff
filecontainer = Await response.GetContentAsStreamAsync()
"Filecontainer is a string."
This doesn't make sense. GetContentAsStreamAsync doesn't return a String. It returns a Stream.
You probably want code like this:
Dim response = Await dbx.files.BeginDownload(path + "/" + file)
Dim responseStream = Await response.GetContentAsStreamAsync()
Using localFileStream As File.Create("myfile.exe")
responseStream.CopyTo(localFileStream)
End Using - Anton U.10 years agoNew member | Level 1
@Gregory, no. It's bigger, mostly. Depends on encoding. If I use ASCII enconding, then it's smaller.
@Steve, thanks, your solution worked. Kinda. I'm a little bit rusty with VB, since I didn't use it for a long, long time. In fuction I did responsestream, and later, I had to return stream in class (form1), because file.create apparently doesn't work in async functions.
Below is entire code, so you can see what I did.
Imports System
Imports System.IO
Imports System.Text
Public Class Form1
Dim dropbox As New Dropbox.Api.DropboxClient("My token")
Dim responsestream As Stream
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.LoadGetDbxUser()
GetExe("/my_path", "exefile.exe")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Using stream = File.Create("exefile.exe")
responsestream.CopyTo(stream)
End Using
End Sub' Dropbox Api functions
Public Async Function GetDbxUser() As Task
Dim user = Await dropbox.Users.GetCurrentAccountAsync()
'Just to check that it actually works
Label2.Text = "User set complete!"
Label3.Text = user.Email
End Function
Public Async Function GetExe(path As String, file As String) As Task
Dim response = Await dropbox.Files.DownloadAsync(path + "/" + file)
responsestream = Await response.GetContentAsStreamAsync()End Function
End Class
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
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, Facebook or Instagram.
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!