MySQL不返回base64网址

时间:2019-06-09 19:42:58

标签: sql ajax buffer

我使用ajax将数据发送到服务器并将其写入mysql。我的表格中有一个上传的文件。在服务器中,我捕获了上传的图像文件并将其转换为base64并将其写入sql。但是我的问题是,当我在前端再次使用ajax取回它时,我收到了缓冲区类型,缓冲区的数据是数字数组而不是base64。 我不知道这些数字代表什么?为什么它不返回我保存的base64?


我检查了数据库,确定已在其中保存了base64。请帮忙。谢谢

{type: "Buffer", data: Array(4640)}
data: (4640) [47, 57, 106, 47, 52, 65, 65, 81, 83, 107, 90, 74, 82, 103, 65, 66, 65, 81, 65, 65, 65, 81, 65, 66, 65, 65, 68, 47, 50, 119, 67, 69, 65, 65, 107, 71, 66, 120, 77, 84, 69, 104, 77, 83, 66, 120, 73, 86, 69, 104, 85, 87, 70, 82, 85, 86, 70, 82, 103, 87, 69, 82, 103, 89, 70, 82, 99, 82, 70, 120, 89, 87, 70, 120, 85, 83, 70, 120, 85, 89, 72, 105, 103, 103, 71, 82, 111, 108, 72, 82, 85, 86, 73, 84, 69, 105, 74, 105, 107, 114, …]
type: "Buffer"

我想要这个BASE64到返回,这是我保存在DATABSE / 9J / 4AAQSkZJRgABAQAAAQABAAD / 2wCEAAkGBxMTEhMSBxIVEhUWFRUVFRgWERgYFRcRFxYWFxUSFxUYHiggGRolHRUVITEiJikrLi4uFx8zODMsNygtLisBCgoKDg0OGxAQGzclICU3KzUwNTc1Ky01KzcrLS0rMDMxLSsuODI3LTYrLTcyLS8vLS0vLS0uLTAtLS0tNy0tLf / AABEIAOEA4QMBIgACEQEDEQH / xAAcAAEAAQUBAQAAAAAAAAAAAAAABgECBAUHAwj ....

GET THE USER FILE AND POST IT TO THE SERVER

      $("#seenButton").click(function(event){
          event.preventDefault();
          var form = document.querySelector("#seenform");
          var data = new FormData(form);
         // console.log('DATA' + data);

          $.ajax({
              url: "/submitseen",
                type: 'POST',
                data: data,
                processData: false,
                contentType: false,
                cache: false,
                success: function(data){
                    console.log(data);
                },
                error: function(e){
                    console.log(e);
                }
            })
        })

RETRIEVE THE FORM DATA BACK , HTML file

 $('#missingsubmit').click(function (e) {
            e.preventDefault()



            $.ajax({
                url: 'loadedmissing/',
                type: 'POST',
                dataType: 'json',
                success: (data) => {
                    console.log(data)

                }
            })
        })
IN THE SERVER, LOAD DATA FROM DATABASE
app.post('/loadedmissing', function(req,res){

    connection.query("SELECT * FROM missingTable", function(error,rows,fields){
        if(error){
            console.log('Error in the query')
        }
        else{
            console.log('successful query')
            res.status(201).json(rows);// send all data (rows) to the ajax request
        }
    })
})

0 个答案:

没有答案