douqi3913 2013-06-16 03:26
浏览 36
已采纳

将blob从android插入oracle

I'm working with Oracle database. I use PHP for my web service and Android as the client which will send blob data to Oracle DB. I use this code

Bitmap imageUpload = BitmapFactory.decodeFile(picturePath); ByteArrayOutputStream baos = new ByteArrayOutputStream(); imageUpload.compress(Bitmap.CompressFormat.JPEG, 60, baos); byte[] image_data = baos.toByteArray(); String converted_image = Base64.encodeBytes(image_data);

to decode and send it as base64 encoding, then send it to the web service with this code

ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("TITLE", title));
            nameValuePairs.add(new BasicNameValuePair("IMAGES", converted_image));
            json = jsonParser.makeHttpRequest(url, "POST", nameValuePairs);

This is my PHP code to insert to oracle db

if(isset($_POST["TITLE"]) && isset($_POST["IMAGES"]))
{
    $title = $_POST["TITLE"];
    $image = $_POST["IMAGES"];
    $gambar = file_get_contents($image);

    $query = "INSERT INTO images (TITLE, IMAGES) VALUES (:TITLE, EMPTY_BLOB()) RETURNING IMAGES INTO :IMAGES";
    $parse = oci_parse($connect, $query);

    $lob_a = oci_new_descriptor($connect, OCI_D_LOB);

    oci_bind_by_name($parse, ":TITLE", $title);
    oci_bind_by_name($parse, ":IMAGES", $lob_a, -1, OCI_B_BLOB);
    oci_execute($parse, OCI_DEFAULT);

    if($lob_a->save($gambar))
    {
        oci_commit($connect);
        $lob_a->free();
    }
    else
    {
        oci_rollback($connect);
    }
}

The PHP code successfully insert the query to the oracle db, but when I see the record the blob does not show anything like this

enter image description here

enter image description here

  • 写回答

1条回答 默认 最新

  • dsh7551 2013-06-24 12:15
    关注

    I think the best solution to this question is to use web service, encode the picture with base64 encoding then decode it while the file transferred.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题