I have been working on doing this for quite some time within AppInventor, but the tools required on board are just not quite there to do it yet. However, I have come up with a “slingshot” solution using a combination of web technologies that will get a file from your device up to google drive.
In order to achieve this, you will require the following:
- A google web app
- An https web server with php and ftp access
- A couple of php scripts / pages
- Ai2 developed app
Credits to Scott Ferguson for the postfile howto, Digital Inspiration for the bones of the apps script, and to Taifun for the File extension 🙂
Again I assume that you have a good grip of AI2, writing and publishing google app script web apps, and the ability to ftp to your web space on an https server (Google Drive will NOT accept urls from non https servers)
The workflow goes something like this:
- In the app, select a file, including the full path
- Once we have this, upload the file to the https server directory
- On completion of the upload, trigger the google web app, by sending the url to the file on the web server to it
- Once the web app has uploaded the file, delete the file from the web server
On the app:
I used Taifun’s File extension to access a list of files from the sdcard, based upon extension – gif,jpg,png,pdf – this list can be extended, or developers can simply use * to get all files.
It was then simply a case of working through three web calls to post the file, upload to drive, then delete the initial posted file for clean up purposes.
Setting up the php and web server
FTP into your https server web space and create a directory, in my case called “AI2”. Inside that directory, create a directory called “uploads” or something similar. I set permissions for “uploads” to 777, not sure if this was necessary. Upload a file using FTP and identify the url (if you use an image file it will be easier to view this in a browser). You will need this url later. Should be something like:
Now we create to simple php files, one which will save the uploaded file to the https server space, the other that will delete it.
Note: the delete function can be very dangerous, use with caution and do not release the full url to anyone else. There is a failsafe included which should restrict any deletions to the upfiles directory. Given the plan is to remove any files once they have been transferred to google drive, means that in practice this shouldn’t be a problem…
Upload these two files to your AI2 directory using FTP
The Google Web App
The web app requires to be fed with the url, discovered earlier, of the file uploaded. This is constructed on the AI2 app and sent using the web component. On successful completion, the web app returns happiness to the AI2 app, which then sets about deleting the original uploaded file from the https server
The google app script:
The AI2 demo app for this, on screen, is fairly uninspiring, a listpicker to fetch the file, an upload button, and success is demonstrated by the return of the filename