简体   繁体   English

如何为Android应用程序在Parse.com中检索图像的文件名

[英]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. 名为“ questionImage”的字段存储这些图像。

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". 例如,上表中的第一个对象具有名为“ 5D_C.png”的图像。 How can I get that name using Java in Aandroid? 如何在Aandroid中使用Java获得该名称? I am using Eclipse, if that makes any difference. 我正在使用Eclipse,如果有什么不同的话。

  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. 例如,如果我没有任何图像字段,则可以制作一个Excel数据表并将其作为CSV导出到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. 首先,您必须进行一个Parse查询以获取您感兴趣的对象。请参见此处,然后在回调中,可以遍历这些元素以收集文件名。 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). 解析并非旨在进行大量操作(批处理操作非常有限)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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