【问题标题】:storing image in database is bad idea then what is the alternatives?将图像存储在数据库中是个坏主意,那么有什么替代方案?
【发布时间】:2015-07-16 18:12:17
【问题描述】:

我读了很多堆栈溢出帖子,说在数据库中插入图像是不好的

Storing Images in DB - Yea or NayStoring image in database directly or as base64 data? 等等。

这件事对我来说仍然不明显在哪里保存图像?在服务器的文件中 ?.在我的应用程序中,用户将上传几张图片并在他的个人资料中查看它们。

一个例子将不胜感激。

我现在做了什么(我现在不是那么好,但我正在学习..)

            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) {

【问题讨论】:

    标签: android


    【解决方案1】:

    如果您的图像重量(2KB-4KB),您可以保存在数据库中

    如果您的图像超过此重量,我建议使用 SD 卡。

    【讨论】:

    • 如果有很多用户在应用程序中发布图像.. 我应该将图像保存在哪里?
    • 喜欢 Facebook 还是 Tw?或者你知道和你的应用类似的例子?
    • 是的,比如 fb,我的应用示例是什么意思
    猜你喜欢
    • 2023-04-05
    • 2020-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 2011-12-03
    • 1970-01-01
    相关资源
    最近更新 更多