简体   繁体   中英

How to retrieve the file name of an image in Parse.com, for an Android app

I am storing small images inside a table. The field called "questionImage" is storing these images.

The table looks as follows:

表

I have two questions:

  1. How can I retrieve the file name of the image files? For example, the first object in the table above has an image named "5D_C.png". How can I get that name using Java in Aandroid? I am using Eclipse, if that makes any difference.

  2. Is there a way to import these images in a batch? For example, if I didn't have any image fields, I could have made an Excel sheet of my data and exported it as CSV into Parse.com. Is the same workflow achievable with image fields inside a class?

First you have to make a Parse query to obtain for the objects you are interested in. See here Then, in the callback, you can iterate over these elements to collect the file names. Something like this:

public void done(List<ParseObject> objsList, ParseException e) {
    if (e == null) {
        Log.d("score", "Retrieved " + objsList.size() + " things");

        ArrayList<String> fileNames = new ArrayList<>();
        for (ParseObject ob : objsList) {
            //This is the important part
            String fileName = ob.getParseFile("questionImage").getName();
            fileNames.add(fileName);
        }

    } else {
        Log.d("score", "Error: " + e.getMessage());
    }
}

Similarily, if you want to obtain the files, you can (in the same interation), get the file and save it

 byte[] bitmapdata = ob.getParseFile("questionImage").getData();
 Bitmap bm = BitmapFactory.decodeByteArray(bitmapdata, 0, bitmapdata.length);
 //Save bitmap in a file

Hope this helps.

UPDATE : not sure if I understood correctly your question. With "import" you mean get the images from parse or upload them to parse. Parse is not designed to make massive operations (batch operations are quite limited).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM