简体   繁体   中英

Get file from parseObject

It's less android question and more Parse.com question, but I need your help:

I have an image file in a table in my application at 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"

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.

If Statics.COL_IMAGE_FILE is a File column, you should do the following to get 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();

        }
      }
    });

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