Created
July 11, 2019 04:43
-
-
Save slavkoder/836c4bba40ce17a3ce9de3cdee3e70be to your computer and use it in GitHub Desktop.
A snippet demonstrating uploading an image and posting to Parse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final String description = ""; | |
// Create ParseFile to save image from camera on Parse backend | |
final ParseFile imageFile = new ParseFile(photoFile); | |
// make an async call to save image on backend | |
imageFile.saveInBackground(new SaveCallback() { | |
@Override | |
public void done(ParseException e) { | |
if (e == null) { | |
// if upload is successful let's create and save post | |
final Post post = new Post(); | |
post.setDescription(description); | |
post.setUser(ParseUser.getCurrentUser()); | |
post.setImage(imageFile); | |
post.saveInBackground(new SaveCallback() { | |
@Override | |
public void done(ParseException e) { | |
if (e == null) { | |
// now you want to package Post and return it to calling activity | |
Intent result = new Intent(); | |
result.putExtra(Post.class.getSimpleName(), post); | |
// if your are in CaptureActivity you can do this: | |
setResult(RESULT_OK, result); | |
finish(); | |
} else { | |
Log.d("CaptureImage", "Error creating an InstaPost: ", e); | |
} | |
} | |
}); | |
} else { | |
Log.d("CaptureImage", "Error uploading image: ", e); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment