使用Worklight SQL适配器从DB2存储和检索图像? [英] Storing and Retrieving images from DB2 using Worklight SQL Adapters?

查看:123
本文介绍了使用Worklight SQL适配器从DB2存储和检索图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 DB2 数据库中的图像存储为 BLOB 内容。我使用 JS 将图像内容转换为 base64

I'm trying to store images in DB2 Database as BLOB contents. I used JS to convert the image content to base64.

 function loadImageFileAsURL()
{
var filesSelected = document.getElementById("inputFileToLoad").files;
if (filesSelected.length > 0)
{
    var fileToLoad = filesSelected[0];

    var fileReader = new FileReader();

    fileReader.onload = function(fileLoadedEvent) 
    {
        var textAreaFileContents = document.getElementById
        (
            "textAreaFileContents"
        );

        textAreaFileContents.innerHTML = fileLoadedEvent.target.result;
        var ImgContent = fileLoadedEvent.target.result;
        $("#IMAGE").attr("src",ImgContent);

    };

    fileReader.readAsDataURL(fileToLoad);
}
}

现在我需要转换这个 base64 内容到二进制,并将它们存储到我的 DB2 数据库。有没有办法在JavaScript中执行此操作?

Now I need to convert this base64 content to binary and store them to my DB2 Database. Is there any way to do this in JavaScript?

如何从数据库中获取这些数据,并使用适配器将其显示在我的移动应用上? / code>。 ?

And how to fetch this data from the database and display it on my mobile app using Adapters. ?

推荐答案

为什么不将图像编码到数据库中的base64?我认为这样做会更好...

Why do you not simply store the image as encoded to base64 in database? I think this would be better in your scenario...


  1. 你收到一张图片

  2. 你使用一些库来处理base64的编码

    查看这个问题:在客户端JavaScript中进行Base64编码和解码

  3. 将数据库中的图像存储在数据库中

  4. >当您需要在应用程序中显示图像时,获取内容并对其进行解码(请参阅步骤2)

  1. You receive an image
  2. You use some library to handle the encoding to base64
    Review this question: Base64 encoding and decoding in client-side Javascript
  3. You store the image-now a string, in the database
  4. When you need to display the image in the app, fetch the contents and decode it (see step 2)

这篇关于使用Worklight SQL适配器从DB2存储和检索图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆