Domanda

I have a class that extends parse object. I am trying to add a bitmap to the instance of this object. I get an error that I can't find any info on:

java.lang.IllegalStateException: Unable to encode an unsaved ParseFile.

I get this error only when adding to the object, not when saving the object.

Here is how I retrieve my image: (Error is on the last line)

 Uri selectedImage = imageReturnedIntent.getData();
                String[] filePathColumn = {MediaStore.Images.Media.DATA};

                Cursor cursor = getContentResolver().query(
                        selectedImage, filePathColumn, null, null, null);
                cursor.moveToFirst();

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex);
                cursor.close();

                Bitmap bitmap = BitmapFactory.decodeFile(filePath);

                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
                final byte[] data = stream.toByteArray();
                ad.addPicture(new ParseFile("image.png", data));

The last line is where the error is thrown. Like I said, I have a class that extends ParseObject. Here is that method in that class:

public void addPicture(ParseFile... pic){
    for(ParseFile pf : pic){
        add(PICTURE, pf);
    }
}
È stato utile?

Soluzione

read docs on android files...

Working with uploaded file is two steps on parse.

  1. Post the file which returns a URL type file handle (Url, name)
  2. work with parse object's field that is pointer to the Url of the uploaded file

The examples in android show that process #1 uses

file.saveInBackground();
ParseObject jobApplication = new ParseObject("JobApplication");
jobApplication.put("applicantName", "Joe Smith");
jobApplication.put("applicantResumeFile", file);
jobApplication.saveInBackground();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top