0

i'm getting the the following error bad json response: org.json.JSONException: Value Invalid of type java.lang.String cannot be converted to JSONObject. can any one tell me how to convert a file to bytes in android and store it in parse cloud...

            InputStream inputstream=assetmanager.open("lmh.jpg");
            byte[] data=new byte[inputstream.available()];                  
            ParseFile file = new ParseFile("lmh.jpg", data);
            file.saveInBackground(new SaveCallback() {

                @Override
                public void done(ParseException e) {
                    // TODO Auto-generated method stub
                    if(e!=null)
                        Toast.makeText(getApplicationContext(), "ERROR: "+e, Toast.LENGTH_LONG).show();
                    else
                        Toast.makeText(getApplicationContext(), "sucess", Toast.LENGTH_LONG).show();
                    }
                });
                ParseObject fileu = new ParseObject("FileU");
                fileu.put("image", file);
                fileu.saveInBackground(new SaveCallback() {

                @Override
                public void done(ParseException e) {
                    // TODO Auto-generated method stub
                }
            });
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
});
sam
  • 2,780
  • 1
  • 17
  • 30
durga
  • 1
  • 3

1 Answers1

0

In your code, you are just passing empty byte array. You should first try to convert your image into byte array appropriately:

// make sure image path is correct

InputStream inputStream=assetmanager.open("lmh.jpg");
bitmap = BitmapFactory.decodeStream(inputStream);

ByteArrayOutputStream byteArrayOS= new ByteArrayOutputStream();  
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOS);
byte[] data= baos.toByteArray();

ParseFile file = new ParseFile("lmh.jpg", data);

Also, make sure your client key is copied correctly: similar error

sam
  • 2,780
  • 1
  • 17
  • 30