Question

I have following JSONObject of JSONArray

{
    "__type": "File",
    "url": "http://files.parse.com/fc5a8795-34a6-4a80-b574-40a647f7949f/f90e5116-05ce-4664-81a9-8448d4914bf7-file",
    "name": "f90e5116-05ce-4664-81a9-8448d4914bf7-file"
}

I want to get file from it... how can I get it?

Was it helpful?

Solution

whats the mimetype of the data you stored as file on parse?

Normally when you upload to parse you provide a file name to the parse api (including ".typ" ) that will indicate a mimetype to any subsequent GET requests. Those gets can just wrap http protocol with the parse remote data to have a single 'provider' type operation that simply consumes the data from parse in a single operation.

For example a media player can open/Play parse data directly when using a file Url like yours. If you store an mp4 on parse with a filename ending in ".mp4" you can simply open the Url to the parse file in a client app like VLC.

For you, you can just create a new HttpUrlConnection and read then data into an appropriate Object.

example where url is a parse.com FILE url like yours:

   URL imageUrl = new URL(url);
    HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
    conn.setConnectTimeout(30000);
    conn.setReadTimeout(30000);
    conn.setInstanceFollowRedirects(true);
    InputStream is=conn.getInputStream();
    OutputStream os = new FileOutputStream(fileCache.getFile(url));
    Utils.CopyStream(is, os);
    os.close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top