Storing an image in a database is a bad idea, what are the alternatives?
I have read a lot of stack overflow posts that say that inserting images into the database is bad.
Saving images to DB - Yea or Nay and Saving an image to a database directly or as base64 data? and many others.
the thing is still not obvious to me , where to save the image? in a file on the server ?. in my application the user will upload multiple images and see them in their profile.
an example would be very valuable.
what i did now (now i'm not so good, but i'm learning ..)
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); //compress to which format you want.
byte [] byte_arr = stream.toByteArray();
String image_str = Base64.encodeToString(byte_arr, Base64.DEFAULT);
//fnish inserting
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username", name));
nameValuePairs.add(new BasicNameValuePair("password", pass));
nameValuePairs.add(new BasicNameValuePair("email", emails));
nameValuePairs.add(new BasicNameValuePair("image", image_str));
System.out.println(nameValuePairs);
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://justedhak.comlu.com/users.php");
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(httpPost);
System.out.println(response);
HttpEntity entity = response.getEntity();
} catch (ClientProtocolException e) {
} catch (IOException e) {
+3
source to share