I’m trying to store some images, that I get as base64 coded strings, in the internal storage.
For some reason they don’t seem to be stored, and I have no clue why.
This is the function that stores them:
public void createImage(String image, String name){
try{
byte[] imageAsBytes = Base64.decode(image.getBytes(), Base64.DEFAULT);
Bitmap img_bitmap = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);
//mCtx is the context. It comes from the main activity
FileOutputStream fos = mCtx.openFileOutput(name, Context.MODE_WORLD_READABLE);
img_bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
fos.close();
//Let's check if they're there
File f = new File(mCtx.getFilesDir().getPath() + "/" + name + ".png");
if (f.exists())
Log.v(DB_TAG, "Exists");
else
Log.v(DB_TAG, "Not exists");
}
catch(Exception e){
e.printStackTrace();
Log.e(DB_TAG, e.toString());
}
}
I keep getting “Not exists” in the logcat. Why can that be?
You are saving your file as ‘name’ and then, the file you created as ‘name.png’.