mergDropboxDownload example

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

simon.schvartzman
Posts: 274
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

mergDropboxDownload example

Post by simon.schvartzman » Tue Jun 20, 2017 11:12 pm

Anybody can share a working example using mergDropBoxDownload?

Have been trying all day to make it work with no success...

Thanks!
Simon
________________________________________
To ";" or not to ";" that is the question

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 670
Joined: Fri Jun 27, 2008 9:00 pm

Re: mergDropboxDownload example

Post by Mikey » Wed Jun 21, 2017 2:14 pm

Simon,
I will be happy to share the example stacks that Monte created to go with the external, but see your other post on this topic, and http://forums.livecode.com/viewtopic.php?f=9&t=29377

simon.schvartzman
Posts: 274
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: mergDropboxDownload example

Post by simon.schvartzman » Wed Jun 21, 2017 2:21 pm

Mikey, many thanks for your replies on both posts.

I will definitely try the new LC library but meanwhile I would appreciate if you send me the working example.

Regards
Simon
________________________________________
To ";" or not to ";" that is the question

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 670
Joined: Fri Jun 27, 2008 9:00 pm

Re: mergDropboxDownload example

Post by Mikey » Thu Jun 22, 2017 1:58 pm

Simon has emailed me off-list, asking for an example using the new LC Dropbox library that is included with LC 9DP7. I told him I would reply here, because I am sure that others are going to ask, as well.

There are no examples using the new library, as yet. It is brand-spanking new. Monte took Gerard McCarthy's Dropboxapi_v2 project as inspiration and wrote LC's library.
I mention Gerard's project, because it is a working stack that you can use to get a feeling for how the different routines work, even though Monte renamed the functions and commands for LC's library.
You can find Gerard's stack here:https://github.com/macMikey/dropboxapi_v2
In the stack there are instructions on how to get your oauth_2 tokens, and the stack is set up to help you play not only with the commands, but with the HTML that it produces, so you can get a good feeling for what to do, and how dropbox responds in various situations.

As I mentioned, LC's Dropbox library took Gerard's code as a starting point, but it is very different. The commands/functions have different names. Monte also did a lot of work to give you the option to use the code asynchronously if you have the an Indy or above license. If you use the code asynchronously, you can make repeated calls, and then as the results are returned process them, instead of running one command at a time. This would be useful if you want to pull several files, for example. I have not gotten far enough along in playing with the library, yet, to see how much of a difference that makes.

simon.schvartzman
Posts: 274
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: mergDropboxDownload example

Post by simon.schvartzman » Sun Jun 25, 2017 11:11 pm

Mikey, I have downloaded Gerard's example and play around with it as per your suggestion. I was able to make it work but I'm having a difficult time to make a simple upload work using LC Dropbox library with LC9.

Would you be so kind to share a very simple example doing just:

Connecting
Upload one file
Download one file

Many thanks in advance!
Simon
________________________________________
To ";" or not to ";" that is the question

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 670
Joined: Fri Jun 27, 2008 9:00 pm

Re: mergDropboxDownload example

Post by Mikey » Sun Jun 25, 2017 11:16 pm

Share the code you are trying to use, and the behavior you are experiencing, and probably more folks than just I can help.

simon.schvartzman
Posts: 274
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: mergDropboxDownload example

Post by simon.schvartzman » Mon Jun 26, 2017 12:50 am

Mikey, to be honest with you I haven't been able to figure out where to start from, ie which function do I have to call to establish the connection in the first place.

Needless to say I can't advance to try an upload until I have the connection established. Or can I? How?

Best!
Simon
________________________________________
To ";" or not to ";" that is the question

Mikey
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 670
Joined: Fri Jun 27, 2008 9:00 pm

Re: mergDropboxDownload example

Post by Mikey » Mon Jun 26, 2017 1:07 am

Go into 9.0 dp7. In the help menu, pick "Dictionary (API)". In the popup menu on the left, select "dropbox". The entire API is there. The top entry has a summary of each command. The workflow is just like the dropboxapi_v2 stack, but the command names are different.

porzucki
Posts: 4
Joined: Sat Feb 14, 2015 8:38 pm

Re: mergDropboxDownload example

Post by porzucki » Sun Jul 30, 2017 12:43 am

I'm new to LC and trying to use dropboxapi_v2. I'm trying to use the Upload and Download functions. Here is a sample of my code
on mouseUp
put "" into Field "Field"
local tData, tFileName
getUploadPath tData, tFileName #get my file's path on my Mac

put "my token goes here" into tAccessToken
put "/" & tFileName into tPath
put "add" into tMode
put "true" into tAutorename
put "false" into tMute
put "downloadComplete" into tCallback

dropboxUpload tAccessToken, tPath, tMode, tAutorename, tMute, tData, tCallback
put it into Field "Field"
end mouseUp

on downloadComplete pRequestID, pHTTPResponseCode, pBinary
put "Status Update:" && return && pRequestID && return && pHTTPResponseCode && return after field "Field"
put "pBinary:" && return && pBinary
end downloadComplete

The results is that a file is created in my dropbox but it's only 79 bytes instead of a 16Kybytes original.

Does anyone have a working example for uploading or downloading to dropbox? What am I doing wrong?
Thanks

simon.schvartzman
Posts: 274
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: mergDropboxDownload example

Post by simon.schvartzman » Sun Jul 30, 2017 1:33 pm

@ porzucki please find below a very simple working Download example. You should see the contents of file "myfile.txt" which you should have previously uploaded to your dropbox path.

Not sure what are you doing wrong but I'd suggest you check what's inside tData before calling the Upload command.
Hope it helps

Code: Select all

on mouseUp
   try
   put "my token goes here" into pAccessToken
      dropboxDownLoad pAccessToken, "/myfile.txt"
      answer it
   catch e
      answer e
   end try  
end mouseUp
Simon
________________________________________
To ";" or not to ";" that is the question

porzucki
Posts: 4
Joined: Sat Feb 14, 2015 8:38 pm

Re: mergDropboxDownload example

Post by porzucki » Sun Jul 30, 2017 10:25 pm

Simon,
Thanks for the quick reply. I tried your code with a text file and it worked, but my use is more general.
How do I download a binary file? Where does the dropbox library routine puts the binary data?
The documentation is not clear:
for uploads what parameter gets the local file system path?
for downloads where is the destination for the binary data?
Thanks for your help
Joe

simon.schvartzman
Posts: 274
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: mergDropboxDownload example

Post by simon.schvartzman » Mon Jul 31, 2017 1:35 am

@ porzucki, i guess you will find the answers by looking into the 2 pieces of code below. The first one for a Download button and the second one for an Upload.
You have to define the folder you want to use as default on your device and you do that using "set the defaultFolder" ...

p.s: I'm using .txt files as an example but the same applies for all kind of files.

Code: Select all

-- Download Example
on mouseUp
   -- define the default folder in your device
   set the defaultFolder to specialFolderPath("Documents")
   try
      put "my token goes here" into pAccessToken
      dropboxDownLoad pAccessToken, "/myfile.txt"
      put it into URL ("file:myDownloadedFile.txt")
   catch e
      answer e
   end try  
end mouseUp

Code: Select all

-- Upload example
on mouseUp
   -- define Upload parameters
   put "my token goes here" into pAccessToken
   put "overwrite" into pMode  //add new file no matter what
   put False into pAutorename  //no autorename
   put True into pMute //do not send notifications
   put "/upLoadedFile.txt"  into pPath  --name of the file inside your Dropbox folder
   put URL ("file:FileToUpLoad.txt") into pData  -- binary data you want to upload
   
   -- define the default folder in your device
   set the defaultFolder to specialFolderPath("Documents")
   try
      dropboxUpload pAccessToken, pPath, pMode, pAutorename, pMute, pData 
   catch e
      answer e
   end try  
end mouseUp
Simon
________________________________________
To ";" or not to ";" that is the question

porzucki
Posts: 4
Joined: Sat Feb 14, 2015 8:38 pm

Re: mergDropboxDownload example

Post by porzucki » Sat Aug 05, 2017 9:54 pm

Simon,
Thanks for the guidance. I had some problems with the use of:
put it into URL ("file:myDownloadedFile.txt")
Your suggestions produce a file which appears like the file you're uploading or downloading (in size and name) to dropbox, but are actually corrupt in some manner.
The native application like excel or word won't open the file.
As an alternate I used the following structure which works correctly:

for download in the callback routine:
open file (tFilePath) for binary write
write pBinary to file(tFilePath) #Data from callback (on downloadComplete pRequestID, pHTTPResponseCode, pBinary)
close file (tFilePath)

for uploads:
open file tData for binary read
read from file tData at 1 until EOF
put it into tBinaryData
close file (tData)

This works for me without file corruption. Hope this will be useful to developers using the dropbox interface.
Thanks for your help
Joe

porzucki
Posts: 4
Joined: Sat Feb 14, 2015 8:38 pm

Re: mergDropboxDownload example

Post by porzucki » Sat Aug 05, 2017 11:09 pm

Simon,
Is anyone maintaining the dropbox library? I found a bug in the code for _function _list_folders_POST
The routine kicked out an error because a string was sent instead of an integer. See Below in my comments:

private function __list_folders_POST pLimit,pActions
if pLimit is empty then put "1000" into pLimit
//old line with error return __CB(__Q("limit") & ":" & __Q(pLimit) & "," & __Q("actions") & ":" & __List(pActions))
return __CB(__Q("limit") & ":" & pLimit & "," & __Q("actions") & ":" & __List(pActions)) #new line
end __list_folders_POST

after I made the change the interface worked as advertised.
joe

simon.schvartzman
Posts: 274
Joined: Tue Jul 29, 2014 12:52 am
Location: Brazil

Re: mergDropboxDownload example

Post by simon.schvartzman » Sun Aug 06, 2017 2:27 am

@ porzucki, good to know you were able to make it work. Not sure about the corruption file you mentioned on my example but anyway I'm happy it helped you to move forward.

Regarding the dropbox library as far as I know it is part of the upcoming Release 9.0 of LC so it should be under QA of the LC development team.

Therefore I would suggest you report the bug at the LC Quality Control Center:

http://quality.livecode.com/

Best
Simon
________________________________________
To ";" or not to ";" that is the question

Post Reply

Return to “Talking LiveCode”