Download DropBox File


#1

How do I download a large DropBox file using the shared link provided by DropBox. When I use the url.createInputStream method, it only reads a small portion of the file.


#2

Have you confirmed what you are receiving is even part of the intended file and not just an error HTML page or some such?


#3

Good call. It is not reading the file and is instead reading an html page related to the DropBox webpage.

Here is the test code:

URL url("https://www.dropbox.com/s/z9505w4b1ue3jou/Bach%20Invention%208%20in%20F.xml");
InputStream *in = url.createInputStream (false, nullptr, nullptr, String::empty, 10000);
File temp( "C:\\temp.xml" );
		
FileOutputStream os( temp );

int totalBytes = 0;
do
	{
	   MemoryBlock mb;
	   int numBytes = in->readIntoMemoryBlock( mb, 1024 );
	   if ( numBytes > 0 )
	   {
		totalBytes += numBytes;
		os.write( mb.getData(), mb.getSize() );
	   }
	   else
		  break;
	}
while ( true );

Here is the direct link if you want to try: https://www.dropbox.com/s/z9505w4b1ue3jou/Bach%20Invention%208%20in%20F.xml


#4

I suppose DropBox has some redirection thing going on that your networking code should attempt to deal with. The wget command line program manages to download the file from the link you provided.


#5

Thanks and that is kind of what I thought, a DropBox issue. I just don’t know enough about this area. Maybe someone else will see this and know exactly what the solution is.


#6

Unfortunately I don’t know much about it either. If I had to do something like this, I would probably just run wget with Juce’s ChildProcess. However distributing the wget binary with one’s app could potentially be problematic because of its GPL license.


#7

Yep, can’t use wget. I am trying to write a simple Downloader for my customers.


#8

You probably need to use their API:

https://www.dropbox.com/developers

Rail


#9

Thanks and I was just looking at it. The API may be a little beyond my skills and I don’t have a lot of time.