user3541743
user3541743

Reputation: 61

android parse store parsefile bitmap in database

I want to able to allow the user to take a picture and save it to parse as a ParseFile in a ParseObject, which I have done, but I also want to save it on my database as either a PasreFile or bitmap. I am unable to save it as a URI because I would have to query it from parse, which I cant when initially saving it.

Database

public class Note {
private String id;
private String title;
private String content;

    Note(String noteId, String noteTitle, String noteContent) {
        id = noteId;
        title = noteTitle;
        content = noteContent;

    }

public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getTitle() {
        return title;
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getContent() {
        return content;
    }
    public void setContent(String content) {
        this.content = content;
    }


@Override
    public String toString() {
        return this.getTitle();
    }

}

Activityone

note = new Note(post.getObjectId(), postTitle, postContent);

and

note = new Note(intent.getStringExtra("noteId"), intent.getStringExtra("noteTitle"), intent.getStringExtra("noteContent"));

Upvotes: 1

Views: 1131

Answers (1)

Edwin
Edwin

Reputation: 531

To save a ParseFile on the database use

ParseFile file = new ParseFile(fileName, byte[]);
file.save();

When you save the file, a url from the file will be created on the server which you will be able to retrieve later on. You will only see the file name you saved on the database.

To save it as a parse file, first convert the drawable to a bitmap if you do not have a bitmap. Then, convert the Bitmap to a byte array.

Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(compressFormat, quality, stream);
byte[] bitmapBytes = stream.toByteArray();

ParseFile image = new ParseFile("myImage", bitmapBytes);
try {
    image.save();
} catch (ParseException e) {
    return null;
}

Upvotes: 1

Related Questions