I am using salesforce for my android app in backend.
and somewhere while using SOQL, I am getting response something like this :
Article_FileNames":"Template.doc"
Article_FileContentTypes":"application/msword
Article_FileBodys":"/services/data/v35.0/sobjects/Hub_Knowledge_Articlekav/xxxxxxxxxxx/Article_FileBodys
ArticleNumber":"000001010
LastPublishedDate":"2015-12-09T20:34:48.000+0000
Now i am not getting, how I can let the user open the file named "Template.doc" on click.
How to open this file ?
is there any file path or id which will linkify this filename ?
Any help will be appreciated!
The only file types that are directly available from outside of your Salesforce instance are images, which are made so by setting the Externally Available Image flag on the Document object itself.
If you need to work with other file types, you're going to have to build them yourself to facilitate their download by the end user. This can be done by querying your instance for the Document, which will contain the Base64 encoded file contents (Body), that array's length (BodyLength), the file extension (Type), and also the file name itself (Name).
Given what you provided, your SOQL query would look something like :
SELECT Body, BodyLength, Name, Type FROM Document WHERE Name = 'Template' AND Type = 'doc'
From there, you should have everything you need to build the file in memory.
Related
I download file from many URLs.
e.g.:
https://myhost/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/00019.jpg
https://myhost/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/0001.jpg
https://myhost2222/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/00019.jpg
https://myhost2222/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/0001.jpg
Now I need to save all download files to Android local folder.
But what is file name must be?
I think to create file name from URL.
But URL contain forbidden characters for file name. So... I thing to create hash (SHA-1) from url or maybe convert URL to Base64.
Is this a good solution?
The idea is to save the file with filename the same as the URL it was downloaded from. This way it will be easy to find it (reconstruct the filename) in the filesystem (cache) given the URL.
So suppose we have this URL: https://myhost/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/00019.jpg
Invalid characters are : and /, so a simple String.replaceAll will remove these characters
String filename = "https://myhost/sh/8n0wli4v5895jom/AAB2E0WA2fetPTLjWtYe5HjAa/00019.jpg".replaceAll(":\\/\\/|\\/", "");
This filename variable equals to: httpsmyhostsh8n0wli4v5895jomAAB2E0WA2fetPTLjWtYe5HjAa00019.jpg
Of course if you want you can instead of completely removing those characters, to replace them with a valid character e.g. -.
make names from time:
String carTime = String.valueOf(System.currentTimeMillis());
String fileName=carTime.substring(carTime.length() - 4, carTime.length())+".jpg"
I think a base64 is good solution if you want a reversed way.
URL => FILENAME (encode base64)
FILENAME => URL (decode base64)
If you just replace : and \ by nothing you lose information and can't
retreive the orginal URL from FILENAME
If you use a Hash fonction you lose information too (and you add a very very very small risk of collision)
Maybe today you don't need a reversed solution but tomorrow for debug you don't know ;-)
Be carrefull : Filenames have limit length
EDIT :
Another solution is to simply create intermediate directory (replacing only https:// by your local temp folder)
I'm developing a strategy game that will have a country full of kingdoms. I want to be able to store and read back in the information of the kingdomgs. I've looked at tutorials online but they just aren't specific to what I'm looking for. So basically:
-Where to store a text file which holds string values.
-The correct file path.
-And how to read from that text file, and check if it is empty.
You can store text data in string resource file:
https://developer.android.com/guide/topics/resources/string-resource.html
Also you can use asset to store text
https://developer.android.com/reference/android/content/res/AssetManager.html
And there is diffrenece:
Difference between /res and /assets directories
My query is almost similar to one asked in the following link :How to get file name when clicking on URL in webview I don't want to use URLUtil for the reasons mentioned there. Also, getting the file name using Content-Disposition header field does not work in my case. I am using Android DownloadManager API for downloading file/images. I have to set destination filename using setDestinationInExternalPublicDir (String dirType, String subPath) method. I have observed that DownloadManager provide name such as "downloadfile.jpeg", "downloadfile-2.jpeg" when any image url is used. I have looked into the DownloadManager source code and found COLUMN_LOCAL_FILENAME and COLUMN_TITLE that might be storing the name of file. How can I get the file/image name as done in DownloadManager API ? If not, is there any way I can detect that these urls does not contain filename at the end so that I can provide my custom name ?
I'm going to get list of files/folders on Google Drive (using Android Google Drive SDK V2). I've found https://developers.google.com/drive/v2/reference/files/list method for this, but i can't see any isFile() or isFolder property or method for the file. How can i do it? I've found kind property but is this what i need?
How can i get full file path for the file on drive?
How can i check the file exists?
Take a look at mimeType. You could have found this easily by looking at the file.list output on the oauth playground since the mimetype contains the word "folder".
"mimeType": "application/vnd.google-apps.folder"
You could also add a q for (Query string) then you can have it return just the folders for you. Then for each folder query its contents. https://developers.google.com/drive/search-parameters
But it depends on what you are trying to do.
Compare the item's mimeType to application/vnd.google-apps.folder - this is the mimeType of a Folder in GDrive.
Every item has a parents property that holds an array of parent folder. I guess you'll have to "manually" browse them and their parents to construct the absolute path of an item. Note that an item might have multiple parent folders.
You can either provide a query parameter in your request that will make the server return only existing files (trashed = false) or check the file's labels after you have fetched the info for that file. Of course this might vary depending on your meaning of "existing"...
In android, i am trying to open an html file from sdcard path to show it in web view . As my path starts with some special character( eg. sdcard/11/#directoryName/index.html), it is not opening that html file . can any one help me to resolve this issue?
Thanks
The character "#" is not a legal character in an URL path. The "#" character is used to reference an "anchor" within a document. Usually used like this:
http://my.host.com/path/to/url#part-of-document
You could try to URL-encode that character in the path so that it doesn't get interpreted as an anchor reference, like this:
file:///storage/sdcard/11/%23directoryName/index.html
but it may be that you will need to read the file yourself and pass the data to the WebView instead.