在javascript中读取文件的Blob并插入数据库

在javascript中读取文件的Blob并插入数据库,javascript,mysql,database,string,blob,Javascript,Mysql,Database,String,Blob,我想从我的js代码中读取任何类型的文件,并将其blob插入到long blob type列中的数据库中。js中的变量将blob读取为字符串,而不是blob 所以我面临的问题是,是否有特殊字符,如单引号/双引号等 读取代码是 function onChooseFile(event, onLoadFileHandler) { if (typeof window.FileReader !== 'function') throw ("The file API isn't supported on

我想从我的js代码中读取任何类型的文件,并将其blob插入到long blob type列中的数据库中。js中的变量将blob读取为字符串,而不是blob

所以我面临的问题是,是否有特殊字符,如单引号/双引号等

读取代码是

function onChooseFile(event, onLoadFileHandler) {
if (typeof window.FileReader !== 'function')
    throw ("The file API isn't supported on this browser.");
let input = event.target;
if (!input)
    throw ("The browser does not properly implement the event object");
if (!input.files)
    throw ("This browser does not support the `files` property of the file input.");
if (!input.files[0])
    return undefined;
let file = input.files[0];
let fr = new FileReader();
fr.onload = onLoadFileHandler;
fr.onloadend = function(event) {
  if (event.target.readyState == FileReader.DONE) { // DONE == 2
    //blobData = event.target.result;
    blobData = new Blob([event.target.result], { type: fileType });

    console.log(blobData);
    console.log(typeof(blobData));
    console.log(blobData instanceof Blob) 
    console.log("-------------------------------------------------");

    blobString = ab2str(event.target.result);
    console.log(blobData);
    alert("file read complete "+blobData.length);
  }
};
document.getElementById('inputHeader').value = file.name;
  fileName = file.name;
  fileType = file.type;
  fileExtension = fileName.split(".").pop();
  fr.readAsBinaryString(file);
}
编写代码是必要的

dataservice.openDocument(document_version_id)
            .done(function (reply) {
                fileExtension = fileName.split(".").pop();
                switch(fileExtension.toLowerCase()){
                    case "doc":
                    case "docx":
                    fileType = "application/msword";
                    break;
                    case "pdf":
                    fileType = "application/pdf";
                    break;
                    case "xls":
                    case "xlsx" :
                    fileType = "application/vnd.ms-excel";
                    break;
                }

                var blob = new Blob([reply.RECORD_DATA.LONG_BLOB], { type: fileType });
                saveAs(blob, 'C:/OutputFile/hello.'+fileExtension);
                deferred.resolve();
            }).fail(function (error) {
                alert("failure in getting document");
                deferred.reject();
            });
        });
请帮助,如何实现这一点


谢谢

您能提供您在问题中尝试过的JavaScript吗?看,你确定这是一个blob的实例吗?尝试日志记录:
console.log(MyBlob instanceof Blob)
。返回真还是假?@Stretch0返回真