Jump to content
Server Maintenance This Week. ×

"Dropbox Sample File with FileMaker with Jon Hogle" -- For FM Go 19?


This topic is 667 days old. Please don't post here. Open a new topic instead.

Recommended Posts

 

Does anyone have this working on Filemaker Go 19?

I implemented this method in a FM Pro 18 Adv database. It works great on my iMac. But, when I move the DB to my iPad I get an error:

 

* Line 1, Column 1

  Syntax error: value, object or array expected.

* Line 1, Column 2

  Extra non-whitespace after JSON value.


 

Set Error Capture [ On ]
# create var to hide/show button on layout
Set Variable [ $$hideOK; Value:1 ]
# start log
Set Variable [ $$log; Value:"" ]
Go to Layout [ “maintBackup” (maintGlobal) ]
Enter Browse Mode
Loop
# create fullpath for backup file
Set Variable [ $filename; Value:Let ([ ts=Get(CurrentTimestamp); yyyy=Year ( ts ); mm = Right("0" & Month ( ts );2); dd = Right("0" & Day ( ts );2); hh = Right("0" & Hour ( ts );2); mn = Right("0" & Minute ( ts );2); ss = Right("0" & Seconds ( ts );2) ]; "Cuts_" & yyyy & "-" & mm & "-" & dd & "_" & hh & "-" & mn & "-" & ss & ".fmp12" ) ]
Set Variable [ $filepath; Value:Get(TemporaryPath) & $filename ]
# save backup to file
Set Variable [ $$log; Value:$$log & "Creating backup... " ]
Refresh Window
Save a Copy as [ “$filepath”; Create folders:No ] [ copy of current file ]
Set Variable [ $err; Value:Get(LastError) ]
Exit Loop If [ $err ]
Set Variable [ $$log; Value:$$log & "Complete" & "¶¶" ]
Refresh Window
# drop the backup into a var for transport
Insert File [ $file; “$filepath” ]
# UPLOAD BACKUP TO DROPBOX
# ----------------------------------------------------------------------------------------------------------
# set dropbox vars to request refresh token
# -----------------------------------------
Set Variable [ $dropboxpath; Value:"/Backups/" & $filename ]
Set Variable [ $dropbox_appkey; Value:"xxxxxxxxxxxxxxxxx" ]
Set Variable [ $dropbox_appsecret; Value:"xxxxxxxxxxxxxxxxx" ]
Set Variable [ $dropbox_refresh; Value:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ]
Set Variable [ $curl; Value:" -d grant_type=refresh_token" & " -d refresh_token=" & $dropbox_refresh & " -u " & $dropbox_appkey & ":" & $dropbox_appsecret ]
# request refresh token from dropbox and store json in $res
Insert from URL [ $res; "https://api.dropbox.com/oauth2/token"; cURL options: $curl ] [ Do not automatically encode URL; Select; No dialog; Verify SSL Certificates ]
# check json for error
Set Variable [ $error; Value:JSONGetElement ( $res ; "error_description" ) ]
Set Variable [ $err; Value:not IsEmpty ( $error ) ]
If [ $err ]
Set Variable [ $$log; Value:$$log & $error & "¶¶" ]
Exit Loop If [ 1 ]
End If
# grab the token for the resulting json and store in $dropbox_token
Set Variable [ $dropbox_token; Value:JSONGetElement ( $res ; "access_token" ) ]
# set dropbox arguments and headers for curl upload
# -------------------------------------------------
Set Variable [ $arguments; Value:Substitute ( JSONSetElement ( "{}"; ["path"; "/Backups/"&$filename; JSONString]//; // ["mode"; "add"; JSONString]; // ["autorename"; True; JSONBoolean]; // ["mute"; False; JSONBoolean]; // ["strict_conflict"; True; JSONBoolean] ); "\""; "\\\"" ) ]
Set Variable [ $curl; Value:"--header \"Authorization: Bearer " & $dropbox_token & "\"" & "--header \"Dropbox-API-Arg: " & $arguments & "\"" & "--header \"Content-Type: application/octet-stream\"" & "--data-binary @$file" ]
Set Variable [ $$log; Value:$$log & "Upload the backup file... " ]
Refresh Window
# upload the backup file
Insert from URL [ $res; "https://content.dropboxapi.com/2/files/upload"; cURL options: $curl ] [ Do not automatically encode URL; Select; No dialog; Verify SSL Certificates ]
If [ 1 ]
Set Variable [ $$log; Value:$$log & $curl & "¶¶" ]
End If
# check json for error
Set Variable [ $error; Value:JSONGetElement ( $res ; "error_description" ) ]
Set Variable [ $err; Value:not IsEmpty ( $error ) ]
If [ $err ]
Set Variable [ $$log; Value:$$log & $error & "¶¶" ]
Exit Loop If [ 1 ]
End If
# grad the name of the file uploaded from the json results
Set Variable [ $name; Value:JSONGetElement ( $res ; "name" ) ]
Set Variable [ $$log; Value:$$log & $name & " Complete" & "¶¶" ]
Refresh Window
# delete the backup file
Set Variable [ $file; Value:"" ]
Set Field [ maintGlobal::gBackupContainer; "" ]
Set Variable [ $$log; Value:$$log & "Deleting the backup file... " ]
Delete File [ Target file: “$filepath” ]
Set Variable [ $err; Value:Get(LastError) ]
Exit Loop If [ $err ]
Set Variable [ $$log; Value:$$log & "Complete" & "¶¶" ]
Refresh Window
Exit Loop If [ 1 ]
End Loop
# if there's was an error, log it
If [ $err ]
Set Variable [ $$log; Value:$$log & "¶¶¶-=Error " & $err & "=-¶" & errorCode ( $err ) ]
Refresh Window
End If
# show the OK button
Set Variable [ $$hideOK; Value:0 ]
Refresh Window

 

Edited by JamesBand
Link to comment
Share on other sites

I added a global temp field to capture raw results from the cURL inserts. It seems that after the Token Refresh on FM Go 19, which Dropbox is glad to do, Dropbox returns a 404 HTML page as a result to the upload request.

So, I am adding global fields to the DB to hold the Dropbox info so I can actually create a separate Token for the iPad. Maybe Dropbox is binding the token to the device as well. We'll see.

 

 

16 hours ago, JamesBand said:

 

Does anyone have this working on Filemaker Go 19?

I implemented this method in a FM Pro 18 Adv database. It works great on my iMac. But, when I move the DB to my iPad I get an error:

 

* Line 1, Column 1

  Syntax error: value, object or array expected.

* Line 1, Column 2

  Extra non-whitespace after JSON value.

 

 

 

 

 

Link to comment
Share on other sites

OK!  FM Go needs the "-X POST" header and FM Pro doesn't.... But, now I have FM Go uploading 0 byte files to Dropbox rather than the full file that FM Pro sends.

 

19 hours ago, JamesBand said:

 

Does anyone have this working on Filemaker Go 19?

I implemented this method in a FM Pro 18 Adv database. It works great on my iMac. But, when I move the DB to my iPad I get an error:

 

* Line 1, Column 1

  Syntax error: value, object or array expected.

* Line 1, Column 2

  Extra non-whitespace after JSON value.

 

 

 

 

 

Link to comment
Share on other sites

Well, it is done!!!! FM Go 19 can use this method to upload files to Dropbox!

 

As I reported previously, "-X POST" is required in the cURL headers for FM Go 19 to send the information properly.

Next, the file to be uploaded to Dropbox MUST be stored in a container field. I was using Insert File to variable. While this works on FM Pro, it won't work on Go.

 

I was doing all this work to be able to backup a DB directly to Dropbox and I am so happy I stuck with it. It works very well!

My script Saves a Copy of the DB. Inserts that backup into a Container field on the relevant layout. Copies the contents of the field to a variable called $file and then uploads that file to Dropbox.

Once uploaded, the variable and container field are emptied. I love it when a plan comes together!

 

Thanks to Filemaker Magazine's Peter Petrowsky (from 2018) and Jon Hogle more recently for making this possible!

Edited by JamesBand
Link to comment
Share on other sites

This topic is 667 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.