【问题标题】:inserting and retrieving image in sql server using restful API使用restful API在sql server中插入和检索图像
【发布时间】:2019-03-13 10:30:56
【问题描述】:

我正在使用 mysql 数据库,我想以 blob 格式存储图像。 我想创建一个 jsp 表单来接受文本格式的图像和其他信息以上传帖子(如标题、描述)。从 jsp 页面我想调用 rest web 服务将图像传递到数据库并取回它。 我是新来的,我不知道该怎么做。 请帮我!! 如果可能,请提供示例

【问题讨论】:

    标签: mysql image rest jsp blob


    【解决方案1】:

    有两种方法可以在 sql server 中跟踪图像。

    1.将图像序列化为二进制格式,以便可以将其存储在sql BLOB列中,您始终可以将二进制作为json传递给您的restful Api。
    2. 将图片的路径保存在 varchar 列中,以便您可以从它的物理路径加载。

    在您的情况下,您需要使用第一种方式。

    这可能会有所帮助http://www.informit.com/articles/article.aspx?p=25280

    【讨论】:

      【解决方案2】:

      $(document).ready(function(){
      
      $("#submit").click(function() {
        var fileInput = document.getElementById('image_field');
        var file = fileInput.files[0];
        var formData = new FormData();
        formData.append('file', file);
        var description= $("input#description").val();
          formData.append('description', description);
             $.ajax({
              url: "http://localhost:8080/echo",
              type: "POST",
              data: formData,
               processData: false,
                  contentType: false,
              success: function(response) {
                if(response) {
                  alert(response);
                } 
              },
              error: function (jqXHR, textStatus, errorThrown) {
                      console.log('Error: ' , errorThrown);
             }
            });
            
         });
       });
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <input type="file" id="image_field"><br><br><br>
      <input type="text" id="description"><br><br>
      <input type="submit" id="submit" value="Submit">

      您可以使用 ajax 调用来实现这一点。我希望这会对你有所帮助。

      【讨论】:

        猜你喜欢
        • 2020-10-09
        • 1970-01-01
        • 1970-01-01
        • 2011-01-05
        • 2014-08-13
        • 2012-03-30
        • 1970-01-01
        • 2014-03-19
        • 2012-03-03
        相关资源
        最近更新 更多