1

I modeled my code after their Mealspotting tutorial but for some reason, I can't see the file saved in the Data Browser. Why is that? Here is my code:

private void saveScaledPhoto(byte[] data) {

        // Resize photo from camera byte array
        Bitmap snypImage = BitmapFactory.decodeByteArray(data, 0, data.length);
        Bitmap snypImageScaled = Bitmap.createScaledBitmap(snypImage, 200, 200
                * snypImage.getHeight() / snypImage.getWidth(), false);

        // Override Android default landscape orientation and save portrait
        Matrix matrix = new Matrix();
        matrix.postRotate(90);
        Bitmap rotatedScaledMealImage = Bitmap.createBitmap(snypImageScaled, 0,
                0, snypImageScaled.getWidth(), snypImageScaled.getHeight(),
                matrix, true);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        rotatedScaledMealImage.compress(Bitmap.CompressFormat.JPEG, 100, bos);

        byte[] scaledData = bos.toByteArray();

        // Save the scaled image to Parse
        photoFile = new ParseFile("snyp.jpg", scaledData);
        photoFile.saveInBackground(new SaveCallback() {

            public void done(ParseException e) {
                if (e == null) {
                    ParseUser.getCurrentUser().put("photo",photoFile);
                    Log.d("save status",photoFile.getName() + " is saved!");
                } else {

                    Toast.makeText(getActivity(),
                            "Error saving: " + e.getMessage(),
                            Toast.LENGTH_LONG).show();
                }
            }
        });
    }
shreyashirday
  • 892
  • 1
  • 10
  • 34

1 Answers1

1

You are just forgetting to save your User object: ParseUser.getCurrentUser().saveEventually();

Samuel Barbosa
  • 782
  • 7
  • 18
  • why is it saveEventually() and not saveInBackground()? – shreyashirday Mar 05 '14 at 02:03
  • also, can I still retrieve the files from the User without creating a Photo class? – shreyashirday Mar 05 '14 at 02:05
  • Just because it's simpler. saveEventually will save your photo, eventually (as soon as it can) :) – Samuel Barbosa Mar 05 '14 at 02:05
  • Thanks, can you answer my second question too? – shreyashirday Mar 05 '14 at 02:06
  • Yes, you can. In this case you'll need to create a field for the photo on the user class and associate it to the user object and save it, the same way as the "Photo" class. Are you saving a profile picture? – Samuel Barbosa Mar 05 '14 at 02:07
  • No I'm saving all the photos the user takes and eventually the plan is to display all those photos in a gallery on a different activity. – shreyashirday Mar 05 '14 at 02:12
  • what do you mean associate it to the user object? am I not already doing that? – shreyashirday Mar 05 '14 at 02:14
  • Sorry. Did not noticed. You are. You are just forgetting to save the user object. `ParseUser.getCurrentUser().saveEventually();` In thin case, the photo will be edited everytime you save it. If you want something like an album you should use an array with: `ParseUser.getCurrentUser().add("photos", photo); ParseUser.getCurrentUser().saveEventually();` – Samuel Barbosa Mar 05 '14 at 02:18
  • One more question, how do I retrieve the array if i do ParseUser.getCurrentUser().add("photos,photo); I tried getList("photos) but that returned null. – shreyashirday Mar 05 '14 at 19:02
  • @user3140562 There is an issue when trying to get a list of ParseFile described here: [link](https://parse.com/questions/how-to-get-a-parsefile-from-jsonarray-retrieved-from-cloudcode-in-android) I would try with JSONArray `ParseUser.getCurrentUser().getJSONArray("photos")`, and then, iterate over it and access the url of the photo from each JSONObject. – Samuel Barbosa Mar 05 '14 at 23:16