ReceiveHTTPFile() with DropBox

Just starting out? Need help? Post your questions and find answers here.
User avatar
TI-994A
Addict
Addict
Posts: 2772
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

ReceiveHTTPFile() with DropBox

Post by TI-994A »

I've been using PureBasic's ReceiveHTTPFile() function in many of the examples that I've posted here, to download media files from DropBox. Here are some of those examples:

* hyperlinking images
* playing MOD/XM files
* converting images to monochrome

I've tested, and the links are still active and works from the browser.

However, the ReceiveHTTPFile() function seems no longer able to download from DropBox. Did they change some protocol to disallow this or something?
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Little John
Addict
Addict
Posts: 4812
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: ReceiveHTTPFile() with DropBox

Post by Little John »

Hi TI-994A,

I can confirm your finding.
With the following code (using PB 5.23 LTS x64 on Windows 7)

Code: Select all

url$ = "https://dl.dropboxusercontent.com/u/6548674/davechild_regular-expressions.pdf"

file$ = GetTemporaryDirectory() + GetFilePart(GetURLPart(url$, #PB_URL_Path))
InitNetwork()
Debug ReceiveHTTPFile(url$, file$)
I'm getting a file with the intended name.

But it's a HTML file with this content:
<html>
<head><title>Found</title></head>
<body>
<h1>Found</h1>
<p>The resource was found at <a href="https://dl.dropboxusercontent.com/u/654 ... ons.pdf</a>;
you should be redirected automatically.

<!-- --></p>
<hr noshade>
<div align="right">WSGI Server</div>
</body>
</html>
When I'm opening that URL with Firefox, then Firefox displays the PDF file as usual.
Downloading a file from my own website with ReceiveHTTPFile() works correctly.

It looks to me that on Dropbox there is a redirection, which can't be handled by PB's ReceiveHTTPFile().
User avatar
TI-994A
Addict
Addict
Posts: 2772
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: ReceiveHTTPFile() with DropBox

Post by TI-994A »

Little John wrote:...But it's a HTML file...

...It looks to me that on Dropbox there is a redirection...
Hi Little John, and thank you for that. You're absolutely right! I wouldn't have thought to read the downloaded file.

It does seem that they've added a redirection layer for some reason. I've tried to find a workaround, but unfortunately to no success.

Thanks again. :)
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
infratec
Always Here
Always Here
Posts: 7704
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ReceiveHTTPFile() with DropBox

Post by infratec »

Hi,

look at my code in the other thread.
It finds out the redirection, but than fail, because PB can not handle https.

If you modify the code, you can build a procedure wich returns the redirection address.

Bernd
User avatar
TI-994A
Addict
Addict
Posts: 2772
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: ReceiveHTTPFile() with DropBox

Post by TI-994A »

infratec wrote:...look at my code in the other thread.
It finds out the redirection, but than fail, because PB can not handle https...
Hi Bernd, and thank you. I tried out your code, and it was able to extract the link from the downloaded HTML code; but it was the same one, and not some redirection link.

You mentioned that PureBasic is not able to handle https; then how did it work before? :?
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
infratec
Always Here
Always Here
Posts: 7704
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: ReceiveHTTPFile() with DropBox

Post by infratec »

Hi,

ReadHTTPFile() seams to use the browser engine of the OS.
So https works with ReadHTTPFile().

But that's not PB.

I changed my code to get the redirection, but it only gets back the https path.
And than it has to stop.

But if I look at Little Johns example, I can not detect a difference between the URLs.

Maybe they install a cookie at the first request and check at the second request if the cookie is available.

But unfortunately this does not help you :cry:

Bernd
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

Re: ReceiveHTTPFile() with DropBox

Post by GPI »

I had many problems with ReceiveHTTPFile(), for example that only 1 or 2 KB of a 144kb-File was downloaded.

On a Windows-System you should try "URLDownloadToFile_(#Null,@_net_page,@_net_file,#Null,#Null)" This should handle also HTTPS.
User avatar
TI-994A
Addict
Addict
Posts: 2772
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: ReceiveHTTPFile() with DropBox

Post by TI-994A »

GPI wrote:...On a Windows-System you should try "URLDownloadToFile_(#Null,@_net_page,@_net_file,#Null,#Null)" This should handle also HTTPS.
Thank you, GPI. It works perfectly, even with https (working code with live DropBox link):

Code: Select all

URL.s = "https://www.dropbox.com/s/ewrlaf3vlobb0k0/googleLogo.jpg?dl=1"
fileName.s = GetTemporaryDirectory() + "googleLogo.jpg"
error = URLDownloadToFile_(#Null, @URL, @fileName, #Null, #Null)
If Not error
  RunProgram(fileName)
EndIf
The sad thing is, PureBasic's ReceiveHTTPFile() function is supposed to be cross-platform.


*CODE UPDATE (22/2/2021): Changes in Dropxox's file server structures have rendered direct downloads with the URLDownloadToFile() Windows API function ineffective.

As of this post, Dropbox's file links can once again be downloaded with the ReceiveHTTPFile() function.

Code: Select all

InitNetwork()
fileName.s = GetTemporaryDirectory() + "googleLogo.jpg"
success = ReceiveHTTPFile("https://www.dropbox.com/s/ewrlaf3vlobb0k0/googleLogo.jpg?dl=1", fileName)
If success
  RunProgram(fileName)
EndIf
Last edited by TI-994A on Mon Feb 22, 2021 8:41 am, edited 1 time in total.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Little John
Addict
Addict
Posts: 4812
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: ReceiveHTTPFile() with DropBox

Post by Little John »

TI-994A wrote:You mentioned that PureBasic is not able to handle https; then how did it work before? :?
Yes, that's strange.

In the past, there have been feature requests for ReceiveHTTPFile() to support HTTPS, e.g. here. If these requests are valid, this would mean by implication that ReceiveHTTPFile() did/does not support HTTPS. Unfortunately, in the documentation of ReceiveHTTPFile(), there is no single word about HTTPS.

I would highly appreciate it, if Fred or Freak would write an official statement, whether or not ReceiveHTTPFile() currently does support HTTPS.
Post Reply