Recent

Author Topic: fphttpClient - problem in downloading file from dropbox  (Read 7021 times)

kjteng

  • Sr. Member
  • ****
  • Posts: 262
fphttpClient - problem in downloading file from dropbox
« on: August 28, 2019, 06:13:55 am »
My code below can download files from goodgle drive but not from dropbox (respective url: https://www.dropbox.com/s/vieo9xlf7i24qvy/check2.png?dl=1
https://drive.google.com/uc?id=1gsHFgNeEZfhqgj_l3BUTXAguz7f8-_sB).  Any thing wrong with my code below ?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.bt2fphttpClick(Sender: TObject);
  2. var   Client: TFPHttpClient;
  3. begin
  4.   { SSL initialization }
  5.   InitSSLInterface;
  6.   Client := TFPHttpClient.Create(nil);
  7.   try
  8.     Client.AllowRedirect := true;
  9.     Client.Get(url1.Text, fname);
  10.     Showmessage('Output file: ' + fname);
  11.   finally
  12.     Client.Free;
  13.   end;
  14. end;                  
  15.  

BTW, I have no problem to download the files from the above url using urlmon   ( urlMon.URLDownloadToFile(nil, Pchar(url1.Text), PChar(fname), 0, nil). Howver, urlmon is available in Windows but not Linux.

Appreciate your help.               

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpClient - problem in downloading file from dropbox
« Reply #1 on: August 28, 2019, 06:36:53 am »
Hi kjteng,

this might help but probably not :-(
https://forum.lazarus.freepascal.org/index.php/topic,39206.msg318360.html

I have been working on a similar problem, trying to download from github.  While I can download from many other https sites, not github.  I have noted conversations about managing the redirect response code better, I suspect its more than that. In my case, and maybe yours, the failure happens at connect time, an incorrect redirect response has not yet been received. I think.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

balazsszekely

  • Guest
Re: fphttpClient - problem in downloading file from dropbox
« Reply #2 on: August 28, 2019, 06:46:12 am »
It does not work with FPC 3.0.4, however it works perfectly fine with FPC 3.2.0.

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpClient - problem in downloading file from dropbox
« Reply #3 on: August 28, 2019, 09:06:47 am »
GetMem, which problem does 3.2.0 solve ?

There is the issue about downloading from any https: site, thats actually solved with a few lines of code in the thread I mentioned.

And there is the much harder one of at least one site, github, not working with code that does work with other web sites ?

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

balazsszekely

  • Guest
Re: fphttpClient - problem in downloading file from dropbox
« Reply #4 on: August 28, 2019, 09:27:58 am »
@dbannon
If I run OP's code(FPC 3.0.4), I get the following error: "Invalid protorcol". Adding a user agent or setting redirect to true does not help. However with FPC 3.2.0 everything works out of the box, even without the user agent. All you have to do is add opensslsockets to the uses clauses.
Most likely a bug in fphttpclient(FPC 3.0.4) was fixed in 3.2.0.

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpClient - problem in downloading file from dropbox
« Reply #5 on: August 28, 2019, 09:38:33 am »
GemMem, could I ask a favour ?

Could you try the OP's code and your fpc320 with this file

https://github.com/tomboy-notes/tomboy-ng/archive/V0.23.zip

Its a bit less than one meg big ....

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Thaddy

  • Hero Member
  • *****
  • Posts: 16520
  • Kallstadt seems a good place to evict Trump to.
Re: fphttpClient - problem in downloading file from dropbox
« Reply #6 on: August 28, 2019, 09:44:15 am »
In 3.0.4 you can explicitly set the protocol to  tls 1.1 or higher, or simply use the ssl sources from 3.2.0. There's nothing there that won't compile on 3.0.4.
But I am sure they don't want the Trumps back...

balazsszekely

  • Guest
Re: fphttpClient - problem in downloading file from dropbox
« Reply #7 on: August 28, 2019, 10:00:20 am »
@dbannon
Quote
Could you try the OP's code and your fpc320 with this file
https://github.com/tomboy-notes/tomboy-ng/archive/V0.23.zip
Sure. It works fine(see attached screenshot).

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpClient - problem in downloading file from dropbox
« Reply #8 on: August 28, 2019, 10:05:57 am »
Thanks Thaddy.
Not quite my issue however. I can build a working fphhtClient that connects to and downloads from most https: sites using the tricks mentioned in https://forum.lazarus.freepascal.org/index.php/topic,39206.msg318360.html

But I get an exception (thats hard to trace) if I try to download a file from github.

I'd like to keep my app using release versions of fpc/Lazarus 'cos of plans to get it into debian repos. I know they don't like 'trunk' type build recipes. Sigh ...

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpClient - problem in downloading file from dropbox
« Reply #9 on: August 28, 2019, 10:07:46 am »
Sure. It works fine(see attached screenshot).

Ahh.. thanks GetMem, now you have given me something to think about.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

balazsszekely

  • Guest
Re: fphttpClient - problem in downloading file from dropbox
« Reply #10 on: August 28, 2019, 11:33:22 am »
@dbannon

The attached project works with FPC 3.0.4  too.

PS: You need the openssl libraries on windows(ssleay32.dll and  libeay32.dll)
« Last Edit: August 28, 2019, 11:36:41 am by GetMem »

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpClient - problem in downloading file from dropbox
« Reply #11 on: August 28, 2019, 02:18:45 pm »
The attached project works with FPC 3.0.4  too.
Wow, thank you muchly Getmem. I'll try it tomorrow, getting late here.  Just had a peek, I'm a bit puzzled, you don't seem to be doing anything I am not.

Tomorrow !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

dbannon

  • Hero Member
  • *****
  • Posts: 3212
    • tomboy-ng, a rewrite of the classic Tomboy
Re: fphttpClient - problem in downloading file from dropbox
« Reply #12 on: August 29, 2019, 03:45:37 am »
Yep, that solves my problem ! Sure hope it helps kjteng too.

The key difference between my version, from https://forum.lazarus.freepascal.org/index.php/topic,39206.msg318360.html, and GetMem's is that GetMem sets SSLType to stTLSv1_2, first thread used stTLSv1_1

Evolving standards ?

Thanks GetMem, big help !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

kjteng

  • Sr. Member
  • ****
  • Posts: 262
Re: fphttpClient - problem in downloading file from dropbox
« Reply #13 on: August 29, 2019, 04:10:19 pm »
@dbannon

The attached project works with FPC 3.0.4  too.

PS: You need the openssl libraries on windows(ssleay32.dll and  libeay32.dll)

I got "Access violation" error with your code when trying to download from the following url:
https://www.dropbox.com/s/vieo9xlf7i24qvy/check2.png?dl=1
https://drive.google.com/uc?id=1gsHFgNeEZfhqgj_l3BUTXAguz7f8-_sB

Did I miss anything?

balazsszekely

  • Guest
Re: fphttpClient - problem in downloading file from dropbox
« Reply #14 on: August 29, 2019, 07:51:20 pm »
@dbannon
Quote
Yep, that solves my problem !
I'm glad it's working.

@kjteng
Quote
I got "Access violation" error with your code when trying to download from the following url:
https://www.dropbox.com/s/vieo9xlf7i24qvy/check2.png?dl=1
https://drive.google.com/uc?id=1gsHFgNeEZfhqgj_l3BUTXAguz7f8-_sB

Did I miss anything?
Unfortunately you need FPC 3.2.0. As I mentioned in one of my previous posts, all the links you provided works with 3.2.0

 

TinyPortal © 2005-2018