I want to upload an image in parse cloud server in android. But I am unable to do so.
I have tried the following code:
Drawable drawable = getResources().getDrawable(R.drawable.profilepic) ;
Bitmap bitmap = (Bitmap)(Bitmap)drawable()
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] data = stream.toByteArray();
ParseFile imageFile = new ParseFile("image.png", data);
imageFile.saveInBackground();
Please let me know how can I do it.
I've added a bounty to find the best definitive code for this common problem
Simple code of Imageupload and retriving using Glide to parse.
Image Upload
destination_profile
is File object of you want to upload image path.Image Retriving
img_userProfilePicture_bg
is boject of ImageView where you want to set image.Assuming you have your bitmap file
bitmap
.It is important to convert the Bitmap into
byte[]
and then uploading the Parse File before associating it with the Parse Object.After struggling for several hours here is code segment works for me.
1. Data Member of activity class
2. Starting the camera. Goal is to start camera activity and BmpFileName to store the referrence to file
3. Reading contents from Camera output by overriding onActivityResult. Goal is to get bmp variable valuated.
4. On Save event
// Finish activity in my case . you may choose some thing else finish();
So here are key difference from others
Let me know if it does not work
Use it like this
I hope this will help you..
Save ParseObject in the background
Save in the background with callback
Variations of the save...() method include the following:
Once a ParseObject has been successfully saved on the Cloud, it is assigned a unique Object-ID. This Object-ID is very important as it uniquely identifies that ParseObject instance. You would use the Object-ID, for example, to determine if the object was successfully saved on the cloud, for retrieving and refreshing a given Parse object instance, and for deleting a particular ParseObject.
I hope you will solve your problem..