I am integrating dropbox in my android application. The requirement is to get all file metadata. I have downloaded dropbox sdk and I am able to authenticate user's credentials as well.
I am unable to get all files using this. this provides metadata of only root folder contents
mDBApi.metadata("/", 0, null, true, null);
I need to chain the api calls to get metadata of all files and folders. Now I want to do it lazily, like get 100 files, dump the metadata in local cache and get next 100 files metadata (irrespective of file location, i.e. no matter where the file is, in root or under 10 folders)
I am using "AccessType.DROPBOX" access to get all the contents. I know that there is a parameter for specifying how many files to fetch in one go ("0" in the above statement) but I want to keep fetching metadata till all data has been received in my client. Is there a way for this or a sample code may be.
Thanks.
The Dropbox API metadata call is meant only for retrieving a single file or folder's metadata. The best practices page indicates that you should not recursively call this endpoint:
https://www.dropbox.com/developers/reference/bestpractice
You may instead be interested in using the delta call to build and maintain your local state:
https://www.dropbox.com/developers/core/api#delta
Related
Is it possible to set the file modified date on Android 11 without the all files access permission?
I tried using the createWriteRequest from the mediastore api. But that does not let you use the File API to call setLastModified. It only allows to update some data via ContentResolver.
updating the last_modified column is not permitted:
https://android.googlesource.com/platform/packages/providers/MediaProvider/+/master/src/com/android/providers/media/MediaProvider.java#6361
you will run into a warning: "Ignoring mutation of last_modified..."
Reason is commented in above inked source code:
Column values controlled by media scanner aren't writable by
apps, since any edits here don't reflect the metadata on
disk, and they'd be overwritten during a rescan.
..which makes sense.
Using the DocumentContract to update the last modified date does not work either
via ContentResolver and DocumentsContract.Document.COLUMN_LAST_MODIFIED
I am making a flutter app where i have to download files from the a distant server.
but I want to make those files only accessible from my app, and not from other file managers or other apps like Netflix does with their app.
how can I achieve that in flutter?
thank you in advance.
you can use flutter_cache_manager
A CacheManager to download and cache files in the cache directory of the app. Various settings on how long to keep a file can be changed.
It uses the cache-control http header to efficiently retrieve files.
example
var file = await DefaultCacheManager().getSingleFile(url);
How it works
By default the cached files are stored in the temporary directory of the app. This means the OS can delete the files any time.
Information about the files is stored in a database using sqflite. The file name of the database is the key of the cacheManager, that's why that has to be unique.
This cache information contains the end date till when the file is valid and the eTag to use with the http cache-control.
Today, I'm implement Google Drive API for Android. I create a folder /Demo/App/Photos and keeps DriveId of Photos to SharedPreferences and I create files or folders here.
Everything ok. I'm try remove /Demo and Empty trash via (https://drive.google.com). Problems here, when I run Android app again, ResultCallback code always success when create files, folders or check MetadaResult with folder never existing in Google Drive. Any suggests?
Since the Drive Android API supports offline functionality, it comes with a caveat that the local cache can sometimes be out of date. I suggest using requestSync. This method should not be called too frequently as it is rate limited but should be fine to call when your app starts to ensure local cache is up to date.
Note that create file requests can also fail even if local cache is up-to-date, say for example file was created when the device was offline and parent folder was deleted before the file could be uploaded to the server. To have guarantees on your creation request try using ExecutionOptions in the CreateFile request to get notified about the success/failure state when the file is created on the server.
The user scenario is as the user use the application to request the files in the router, the router would send back a file string.(like JASON file but not)
It contains files or directories information. After parsing the string, it will create an object array so that I can push it to the adapter of a listview. As the user press on the directory icon, it would send an http request to request the file string again even if the files or directories information remains the same.
I just wonder whether I can hash the files and directories information to judge if the data has been changed or not. If it's not changed, I won't have to send another request.
But what information should be hashed and how to do so?
Is there any available plugin?
Please suggest some strategy to reduce the httpoverhead in this scenario.
If you write the files, then yes - you could create a checksum and write it at a known location, only reading entire file if the checksum's changed. That known location could be inside each file, or in a separate file per directory - pros and cons depending on your needs and how files may be changed.
If you don't write the files, you'll have to dig a bit deeper to work out how to do this with whatever insight the router's providing you. If the router-provided directory information includes any time stamps, checksums etc then you may be able to compare to the last time you downloaded the info and deduce which files have changed.
If not, you've no way of knowing if something's changed without downloading the files again, but you could take an attitude like "if it's been less than 10 seconds then who cares if it's changed - just show them the old data"... depends on your app whether that's sane.
If you want a pre-written checksum/hash - perhaps try MD5 - it's often used for file checksums on UNIX/Linux.
My app downloads some assets from my server using an AsyncTask and I put them in a folder on the SD Card. Then, I use these assets in my buttons backgrounds. Everything works, but I'm wondering the best practice to use when I change my assets on the server side. In fact, at the moment, I'm not able to know if the server asset is a new one compared to the one stored locally. However, I was thinking about two possible solutions:
1) The app checks the server for new files, e.g. twice a day. If new files are there, then download them and upgrade the storage locally. In this case: how can I get the time difference between the local and the server file? In other words, how can I know that the server asset is a new one compared to the local one?
2) The server send a notification to the client when a new file is available. How can I manage that?
What is the best choice between the two above?
You can have an assets version number for your assets. Every time your app starts, you can request the latest assets version number. if its larger than the version number you have stored, you know that the images have changed and you can download the latest images. Every time images changes in the server, make sure you increase the version number.
You should also store the version number when you retrieve assets from the server.
I think option 2) ("server send a notification to the client when a new file is available") would require running a Service on the client in order to "listen" to the notification --> This is overkill
What I would do is similar to your option 1) except it is independent from the client and server's clocks:
Version your assets, and store:
On server side, in a txt or xml file, the latest version of each asset available on the server
On client side, the current version of each asset the version number of the latest
On client side, you would then periodically retrieve the txt/xml file, and determine if you need to download new assets.
You could add some code on the server to compute the MD5 sum of a file, and then from the Android app, make a request to e.g. http://hostname/getMD5?file=myfile.abc, and if the MD5 sum differ from the local one, download the file again.
As for notifying the phone, I don't think that's possible. But it might be OK to poll every 30 mins or so, since you only need to fetch a short string.
Add a version file to your server, something simple such as like this one would work:
version.txt:
image001.bmp 3
image002.bmp 1
image003.bmp 1
You can download this file as first thing when you connect to server and parse it. Then if you notice a newer version on server, download updated files.