Last active
June 25, 2024 21:21
-
-
Save rooksword/aea11599e3bc62f2f3aec887ce1747af to your computer and use it in GitHub Desktop.
GameMaker script which saves files to Dropbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| How to use: | |
| You can use this function to save a file to Dropbox. | |
| Go to https://www.dropbox.com/developers/apps. | |
| Click 'scoped access', then 'app folder', then name your app, then click 'create' | |
| Go to the permissions tab and select 'files.metadata.write' and 'files.content.write', then click 'submit'. | |
| Click 'settings' and 'generate access token'. Paste that here: | |
| */ | |
| global.std_access_token = "sl.B325p61uAJ5vT7hdkqNcYR-tX82erM39tApUWEbspWh6MZgjpAnH0MHOzXl4q_sOJf2l_K2_sphwKfknm_EDlZxjDzODkrCckvp0vk1sivPF0gwxeRZ0GDS1DlmIhMwxlxqY7LGUaSIK"; | |
| /*Submit | |
| Once you have created an app, you will find a folder in your Dropbox account called 'Apps' and in that folder will be a folder with your app name. Files will be saved here. | |
| Below is some example code to take a screenshot and save that to Dropbox: | |
| var _fname = "image.png"; | |
| screen_save(_fname); | |
| SaveToDropbox(_fname); | |
| file_delete(_fname); | |
| And here is an example for saving a string as a text file: | |
| var _fname = "text.txt"; | |
| var _file = file_text_open_write(_fname); | |
| var _str = get_string("Bug Report:", ""); | |
| file_text_write_string (_file, _str); | |
| file_text_close(_file); | |
| SaveToDropbox(_fname); | |
| file_delete(_fname); | |
| */ | |
| global.std_url = "https://content.dropboxapi.com/2/files/upload"; | |
| function SaveToDropbox(_fname) | |
| { | |
| var _file_data = buffer_load(_fname); | |
| var _http_headers = ds_map_create(); | |
| ds_map_add(_http_headers, "Authorization", "Bearer " + global.std_access_token); | |
| var _api_arg = { | |
| path: "/" + _fname, | |
| mode: "add", | |
| autorename: true, | |
| mute: false, | |
| strict_conflict: false | |
| }; | |
| _api_arg = json_stringify(_api_arg); | |
| ds_map_add(_http_headers, "Dropbox-API-Arg", _api_arg); | |
| ds_map_add(_http_headers, "Content-Type", "application/octet-stream"); | |
| post = http_request(global.std_url, "POST", _http_headers, _file_data); | |
| ds_map_destroy(_http_headers); | |
| buffer_delete(_file_data); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment