I am very new to parse.com. I have a watch search, how to create a profile picture for the user, and I came up with no result. I know how to upload an image on Parse.com, but I don't know how to get it.
this is how i upload the image:
ParseUser user = new ParseUser();
user.setUsername(usernametxt);
user.setPassword(passwordtxt);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
photo.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] image = stream.toByteArray();
ParseFile file = new ParseFile(usernametxt + ".png", image);
file.saveInBackground();
ParseObject imgupload = new ParseObject("ImageUpload");
imgupload.put("ImageName", usernametxt);
imgupload.put("ImageFile", file);
imgupload.saveInBackground();
Toast.makeText(RegisterActivity.this, "Image Uploaded",
Toast.LENGTH_SHORT).show();
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
Intent intent = new Intent(
RegisterActivity.this,
Welcome.class);
startActivity(intent);
finish();
} else {
Toast.makeText(getApplicationContext(),
"Sign up Error", Toast.LENGTH_LONG)
.show();
}
}
});
}
}
This is how I get the image (don't work, throwing an exception): ParseQuery query = ParseQuery.getQuery ("ImageUpload"); query.whereEqualTo ("image_name", currentUser.getUsername ()); query.getFirstInBackground (new GetCallback () {
public void done(ParseObject object, ParseException e) {
if (object != null) {
Toast.makeText(Welcome.this, currentUser.getUsername(),
Toast.LENGTH_SHORT).show();
ParseFile file = (ParseFile)object.get("ImageFile");
file.getDataInBackground(new GetDataCallback() {
public void done(byte[] data, ParseException e) {
if (e == null) {
bitmap=BitmapFactory.decodeByteArray(data, 0, data.length);
profilepic.setImageBitmap(bitmap);
} else {
}
}
});
} else {
Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_SHORT) .show();
}
}
});
if someone looks at the code and tries to let me know what I did wrong, it will help me a lot!
Sorry for my bad english.
user3421416