Page 2 of 3

Re: Dropbox Help

Posted: Tue Mar 15, 2016 1:46 pm
by gmccarthy
eg.Header to include:
Lets say the file name that you clicked on was testfile1.txt in the dropbox app folder.

Authorization: Bearer <<AccessToken>>
Content-Type:
Dropbox-API-Arg: {"path":"/testfile1.txt"}

You might put into a variable the following and just replace MyFilename with the clicked text.
Authorization: Bearer <<AccessToken>>
Content-Type:
Dropbox-API-Arg: {"path":"/MyFilename"}

See the code in the files-download.

Re: Dropbox Help

Posted: Tue Mar 15, 2016 2:08 pm
by Jamie37
Sorry, im struggling to understand fully. I am using the code out of files-download but the part im struggling with is
You might put into a variable the following and just replace MyFilename with the clicked text.
Authorization: Bearer <<AccessToken>>
Content-Type:
Dropbox-API-Arg: {"path":"/MyFilename"}
I have the selected text in a variable but dont know how to use that variable as the file name. Also while I am asking, How would I only show the file name and not the entire path. Sorry for not understanding and im very grateful for your help.

Jamie

Re: Dropbox Help

Posted: Tue Mar 15, 2016 9:40 pm
by gmccarthy
Replace "MyFilename" with the file name.
You can cut the file path as the last "/" in various ways.
eg. set the itemdelimiter to "/" then get item -1 of the file path.

Re: Dropbox Help

Posted: Tue Mar 15, 2016 10:43 pm
by Jamie37
So does this mean I put my variable which contains the filename in the header field or do I put it into code because im really stuck on how to actually use the file name. I know you say replace the filename with my filename but the filename needs to be the variable because thats what contains my filename. Below is the code on the list which is your code...

Code: Select all

global gSelectedFile

on mousedown
   put the hilitedtext of me into gSelectedFile
   show button "View"
end mousedown

on selectionchanged
   put the hilitedtext of me into gSelectedFile
   show button "View"
end selectionchanged
This is the code on the button which also uses your code:

Code: Select all

global gSelectedFile

on mouseUp
   DB2_download
end mouseUp

on DB2_download
   if not fGetDropboxOnline() then
      answer "Dropbox HTTPS connection NOT available for DropBox_API_2"
      exit DB2_download
   end if
   ClearResponseFlds
   --
   put fld "Post_files-download" into tPost
   --put empty into tPost
   put fld "Header_files-download" into tHeader
   put "https://content.dropboxapi.com/2/files/download?" into tURL
   --
   put fGetDropboxAPI2(tHeader,tPost,tURL) into tResponse
   put tResponse into fld "ResponseJson"
   //put fGetResponseTextFromResponse(tResponse) into fld "ResponseText"
end DB2_download
Thanks again
Jamie

Re: Dropbox Help

Posted: Wed Mar 16, 2016 2:34 am
by gmccarthy
You need to use:
put fGetDropboxAPI2(tHeader,tPost,tURL)
You need to put hold the various inputs to the function in the variables: tHeader,tPost,tURL
You can put the file name selected into a variable then use that variable to replace the header text in another variable.

Re: Dropbox Help

Posted: Thu Mar 24, 2016 11:03 pm
by Jamie37
Hi gmccarthy,

Sorry for the late reply, I have been very busy. I have sorted the problem I had with being able to click the file and os on and thats working great. Going back to the other thing I wanted to do. It was to just show the file name. When I use your suggestion of Item -1, I only get the very last file as I have three files in the folder at the minute and there will probably be more. Is there a way to just show the the file name of each file?

Thanks
Jamie

Re: Dropbox Help

Posted: Thu Mar 24, 2016 11:45 pm
by gmccarthy
You can do a repeat loop through the paths and collect the last items and just list them.

Re: Dropbox Help

Posted: Fri Mar 25, 2016 12:05 am
by Jamie37
I have a repeat loop in place now to try it but the problem is that it gets the last item of each line but will then only put the last item of the last line into the field. THis si the repeat code I have:

Code: Select all

repeat for each line tline in tDropBoxFileList 
         put the last of item of tline into tDropBoxFileListLast
         answer tDropBoxFileListLast
         put tDropBoxFileListLast into fld "DropBoxFileList"
      end repeat
Sorry to keep asking but there was one other thing. When I have a file thats the same name for uploading, mine will not upload even when I set the path to automatically add a number to the end like your documentation in the API says? Do you have any ideas why this would be?

Thanks
Jamie

Re: Dropbox Help

Posted: Fri Mar 25, 2016 12:51 am
by gmccarthy
Build a list with a repeat loop on he list of files
eg:
repeat for each line rLine in pText
put fGetlastChunk(pDelim,rLine) & cr after tList
end repeat

Re: Dropbox Help

Posted: Fri Mar 25, 2016 1:09 am
by Jamie37
Im really grateful for your help but if i'm honest I don't really know what that piece of code means. Id rather understand it rather than just copy and pasting. Would you be able to explain it to me if thats ok so I understand.

Thanks
Jamie

Re: Dropbox Help

Posted: Fri Mar 25, 2016 1:23 am
by gmccarthy
get the list of files in the folder
use a repeat loop so that for each file, get the last item
and add it to a list of file names

Re: Dropbox Help

Posted: Fri Mar 25, 2016 2:10 am
by Jamie37
That's Great! Thanks for the explanation. However it is still giving me the full file name and when I use item -1, if still only gives me the very last one?

Re: Dropbox Help

Posted: Fri Mar 25, 2016 2:30 am
by gmccarthy
set your itemdel to slash

Re: Dropbox Help

Posted: Fri Mar 25, 2016 4:35 pm
by jacque
put the last of item of tline into DropBoxFileListLast
When you put something into a variable, it replaces the current value with the new one. As you loop through the files, each loop replaces the previous content until by the end only the last filename remains. If you are trying to make a list, you want to put the new value after the existing list:

Code: Select all

put the last item of tline & cr after DropBoxFileListLast
There was an extra "of" in the original which I removed.

Re: Dropbox Help

Posted: Fri Mar 25, 2016 10:54 pm
by Jamie37
Thank you both for your input. I really appreciate your help and I believe everything is now sorted. Thanks gmccarthy, your Dropbox API is great!

Jamie