How to transfer file from Linux to Android using Google Drive - android

ENVIRONMENT:
I have a system consisting of Android clients and Linux server. Files (jpeg images) are transferred from Android client to Linux server via Google drive OK.
The client uses Drive API to upload the file into the ServerUploads folder on Google Drive
Client informs the server of the file via GCM (Google Cloud Messaging)
ServiceAccount on Server reads the file via REST API
I have this transfer working well.
Later the server needs to send the file (jpeg) to other clients based on search criteria, location, the view area, etc. So I try to reverse the flow to transfer the jpeg file to clients.
Service Account on Linux server uploads the file to ClientDownload folder on Google Drive
The server notifies client(s) of the file via GCM
The client tries to download the file via Drive API but fails due to protection
The app and ServiceAccount are both associated with the application in the developer's console.
The email associated with the App and ServiceAccount are different domains. (This is not Google Apps for Work.)
PROBLEM:
Since the newer Android Drive API with Google Play Services only supports Drive.SCOPE_FILE the app does not have access to files created by Service Account on Linux.
Is it possible on the server using REST API to add/change ownership of the file so the client can read the file with Drive?SCOPE_FILE? My attempts on this path so far have failed. Trying to insert new ownership fails with a status saying it's not yet implemented. Updating permissions to provide the app with ownership reports insufficient permissions for this file. Trying to patch the permissions give similar failure message. However, I am new to this API and may be doing it wrong.
Is it possible to access the contents of the file using Android DownloadManager service? The best I have done with this path, trying multiple variations of links, is an HTML file which looks appropriate for browser parsing and display: not the contents of the jpeg file. Again, this is a new area for me and I may not be doing it right.
From my research, it appears I can do what I need to do by using the REST API on the Android client, but I really don't want to incur that overhead if there's another path.
At a high level, the documentation (as sparse as it is) implies what I want to do possible. Does anyone have experience with this data flow pattern? If so, what's the appropriate way for the client to read the file created by the Service Account on the Server?
Thanks in advance!

After a few more days of exploring various rabbit holes I was able to download the file using Android DownloadManger. The trick was composing the correct query parameters in the HTTP request URI:
https://drive.google.com/uc?export=download&id=[resourceId]
Also the google drive file resource security needs to be 'public' or 'anyone with link' for this to work.

Related

Flutter: Download file from server, edit in third party app, re-upload when edited

Not even sure if this is possible at all, but here's what I need to do (OK means I am able to do this)...
Download file using a REST service, save to device (iOS, Android) - OK, using Dio
Open file in default application (for example Word or similar) - OK, using open_file
The user alters the file some way - can't get this one to work, file is read-only
Returning to my App, I need to re-upload the file if it has been altered - should be easy when I solve 3 and it is possible to determine if the file has been updated since it was downloaded (checking file write date or similar)
Now, the reason the file is read-only I assume is because it is downloaded to my apps storage. Is it possible to downlad a file to a location where the third-party app has write access to said file? Is this stuff even possible on a mobile device? I am writing both the client app and the REST server.
An alternative, I guess, could be to have my server upload the file to Google Drive, OneDrive or similar and have the third party app open the file from there... The user is authenticated, so I guess I could pick up the authentication token (JWT) and use this communicating with OneDrive or similar.
Any ideas?

Verify site for Android Instant Apps without Digital Assets Links and https?

is it possible to use Instant Apps just with Google Webmaster Tools verification (like I did before with app-indexing) -> Search Console
Or maybe, this time it is necessary to use https + DAL? Handling Android App Links
Currently we don't use https, this is why we need the other solution.
I couldn't find the answer in Instant Apps documentation.
Yes, you must use HTTPS and Google Digital Asset Links.
From the second paragraph of your link
Handling Android App Links
Automatic handling of links requires the cooperation of app developers
and website owners. A developer must configure their app to declare
associations with one or more websites, and to request that the system
verify those associations. A website owner must, in turn, provide that
verification by publishing a Digital Asset Links file. A Digital Asset
Links file is a collection of statements conforming to the Asset Links
protocol that make public, verifiable assertions about other apps or
websites.
And later on that same page:
Important: The system verifies the JSON file via the encrypted HTTPS
protocol. Make sure that your hosted file is accessible over an HTTPS
connection, regardless of whether your app's intent filter includes
https.

Correct way to connect to Google Cloud Storage from Android clients

I have been searching around and have found several examples of ways to connect to Cloud Storage from Android clients but these methods are quite old now. This is generally using a p12 file and newer examples show .json files to hold settings.
I have looked at this... https://cloud.google.com/storage/docs/json_api/v1/json-api-java-samples and it sais "Note: This client library is separate from the Google Cloud Storage client library, another option for interfacing with the the JSON API using Java." giving multiple options!
So my question is.. What is the correct way to implement the client (Android) side of Cloud Storage?
The Cloud Storage JSON API Client Library for Java is an older, auto-generated client that is used as the underpinnings for the newer, under-development Google Cloud Java Client for Storage. The latter is part of the google-cloud project, and aims to reduce the amount of boilerplate code needed to interact with the service. If you have a pointer to your Android sample that needs updating, we can take a look.
Another option for mobile development is to use Firebase Storage, which ultimately writes into Google Cloud Storage. Firebase is all about mobile and untrusted clients, and provides additional security rules that allow you to provide access to users that do not have a Google account.

Can a android app using dropbox sync API use the cache, filesystem, files of the locally installed dropbox official app?

I have integrated the dropbox sync api with my native android app. My question is regarding the offline usage of cache, filesystem and files from the official dropbox app.
Setup:-
Device is android phone
Official dropbox app is installed
API used is the sync API
Scenario 1
If my android device is in aeroplane mode and my app is also running in background as a service. A new file is added to the dropbox app. This new file cannot be synced to the dropbox server because there is no network connection. Although my service has registered DbxFileSystem.SyncStatusListener I do not get a callback. Is it because my app does not share the filesystem of the locally installed dropbox app and my app and the dropbox app are treated as two separate clients?
Scenario 2
A new file is uploaded to the dropbox server, and it is immediately downloaded on the locally installed dropbox app by marking it as favorite. Then I put the android device in aeroplane mode. Then I launch the app. On this newly added DbxFile I call the getReadStream(). I observe that the DbxFile is not cached and attempts to connect to the network. Does it mean that I cannot use the downloaded file present in the filesystem used by the official dropbox app installed locally?
If the answer is "No the cache, filesystem and files used by my app and the official dropbox app are different and we are two separate clients for the dropbox server" then what API should I be using to achieve the behavior I want?
No, there's no way to access the Dropbox app's file storage/cache.

Android App : Sending files to the server using the app

I intend to build a simple app to send files from a mobile phone to a remote server.
File size can vary from 500kb to 10 MB.
Is there any service available from Amazon or Google or any other company that will help with the server end side. I did some research about Google Cloud messenger, Pushbullet but they support only short messages.
Best way is to upload files from Android (or iOS with similar APIs) to respective cloud storage directly (not streaming through your server process, but direct to the storage)
Google Cloud Storage Java Client Library to upload to Google-Cloud-Storage by using
GscService.createOrReplace(GcsFilename, GcsFileOptions)
Amazon S3 Android TransferManager to upload to Amazon-S3 by using
TransferManager.upload(bucketNmae, fileName, file)
Both these services are meant for uploading files from a android app to respective cloud directly, without any server code. Then you can do either of
Make the file available to download with a web URL (as CMS).
Use the file inside the cloud in your application (as File System).

Categories

Resources