简体   繁体   English

从parseObject获取文件

[英]Get file from parseObject

It's less android question and more Parse.com question, but I need your help: 这是一个较少的Android问题和更多Parse.com问题,但我需要你的帮助:

I have an image file in a table in my application at Parse.com 我在Parse.com的应用程序表中有一个图像文件

The file is ok, I can manually download it and watch it. 文件还可以,我可以手动下载并观看。

But when trying to get it using parseObject that I alreay get from server, I'm getting "null" 但是当我试图使用我从服务器获得的parseObject来获取它时,我得到“null”

code: 码:

  byte[] imageFile = parseObject.getBytes(Statics.COL_IMAGE_FILE);

What am I doing wrong? 我究竟做错了什么?

ps : I can see the image file data/link in the parseObject "estimatedData" field, but can't get him. ps:我可以在parseObject“estimatedData”字段中看到图像文件数据/链接,但无法得到他。

If Statics.COL_IMAGE_FILE is a File column, you should do the following to get byte[]: 如果Statics.COL_IMAGE_FILEFile列,则应执行以下操作以获取byte []:

ParseFile imageFile = (ParseFile)parseObject.get(Statics.COL_IMAGE_FILE);
imageFile.getDataInBackground(new GetDataCallback() {
  public void done(byte[] data, ParseException e) {
    if (e == null) {
      // data has the bytes for the image
    } else {
      // something went wrong
    }
  }
});

See this code snippet from my application. 从我的应用程序中查看此代码段。 outer query returns the object to which file is associated and inner query results the file from that object. 外部查询返回与文件关联的对象,内部查询返回该对象的文件。 Hope it helps. 希望能帮助到你。

  ParseQuery<ParseObject> query = ParseQuery.getQuery("ClassName");
    query.whereEqualTo("Column", "Your_variable");
    query.getFirstInBackground(new GetCallback<ParseObject>() {
      public void done(ParseObject object, ParseException e) {
        if (object != null) {

            ParseFile file = (ParseFile)object.get("File_Coulumn");
            file.getDataInBackground(new GetDataCallback() {


            public void done(byte[] data, ParseException e) {
                if (e == null) {

                    bitmap=BitmapFactory.decodeByteArray(data, 0, data.length);
                    //use this bitmap as you want

                } else {
                  // something went wrong
                }
              }
            });

        } else {
            Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_SHORT) .show();

        }
      }
    });

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

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