I need to upload some images to a server. This is done with a json object. The json object has 2 values, a timestamp and a Base64 encoded string of the image. I am using the jackson library and was wondering if this is a good way to upload the images. I am worried about memory consumption if I happen to upload images asyncronusly in the future. Here is is...
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
public class Photo {
@JsonIgnore
private String path;
private String id;
@JsonProperty("ts")
private long timestamp;
public Photo(long timestamp, String path) {
this.timestamp = timestamp;
this.path = path;
}
public String getData() {
Bitmap bm = BitmapFactory.decodeFile(path);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 50, baos);
bm.recycle();
byte[] byteArray = baos.toByteArray();
try {
baos.close();
} catch (IOException e) {
e.printStackTrace();
}
return Base64.encodeToString(byteArray, Base64.DEFAULT);
}
}