Download DropBox File

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.

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

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

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.

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.

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.

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

You probably need to use their API:

https://www.dropbox.com/developers

Rail

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.

A little cheat code I found snooping at the URLs that Dropbox generates, is that if you add the “dl” parameter set to 1 to it, it will download the file straight away rather than showing the download page.

so in your case you can solve it by adding:

url = url.withParameter ("dl", "1");

before creating the inputstream.

This will basically download the following URL, which worked in my browser to download the file directly:

https://www.dropbox.com/s/z9505w4b1ue3jou/Bach%20Invention%208%20in%20F.xml?dl=1

Thanks but url = url.withParameter (“dl”, “1”); does not work at all. If fact, no bytes will be read.
This works in Browsers but not in juce code.

Ah, too bad. I always used it in browsers and assumed it could work programmatically as well.
Strange that it doesn’t however. Have you tried also to append “?dl=1” to the URL directly?