我與MongoDB的問題,我有一個Java SOAP Web服務,我的前臺在Angular/Bootstrap/Jquery中,我需要在我的mongo數據庫中保存一個文件,但我不知道如何做這個,我正在嘗試這個爲期3天,我需要一個JQuery/js調用SOAP服務來做這個或者直接使用js的例子,我接收到的文件是<input type="file" id="file"/>
。 謝謝你的幫助。 我的文件類型是帶有json和圖像的tgz,比我需要保存在我的mongo數據庫中的類型要多。在MongoDB中保存文件
function uploadCard() {
var fileList = new Array();
fileList = document.getElementById("file").files;
var fr = new FileReader();
if (FileReader && fileList && fileList.length) {
fr.readAsArrayBuffer(fileList[0]);
imageData = fr.result;
}
jQuery.support.cors = true;
var wsUrl = "http://" + window.location.hostname + ":7004/CardServiceImpl/CardService?WSDL";
var soapRequest = crateCardSoapRequest(document.getElementById("file").files[0]);
$.ajax({
crossDomain: true,
type: "POST",
url: wsUrl,
contentType: "text/xml",
dataType: "xml",
data: soapRequest,
success: processSuccess,
error: processError
});
}
function crateCardSoapRequest(input) {
var req = "<soap:Envelope xmlns:soap=" + '"' + "http://schemas.xmlsoap.org/soap/envelope/" + '"' + ">" +
"<soap:Body>" +
"<ns1:uploadCard xmlns:ns1=" + '"' + " http://card.ejb.card_editor.com.br/" + '"' + ">" +
"<arg0>" +
"<cardBean>"+
"<description>StringValue</description>" +
"<id>23</id>" +
"<name>StringValue</name>" +
"<file>" + input + "</file>" +
"<template>" + "</template>" +
"</cardBean>" +
"<nickNameUser>lucas_santos</nickNameUser>" +
"</arg0>" +
"</ns1:uploadCard>" +
"</soap:Body>" +
"</soap:Envelope>";
}
我的肥皂參數的java.io.File
你說你已經嘗試了三天。你在那段時間嘗試了哪些方法,以及遇到了什麼問題? –
那麼你使用的是Angular還是jQuery?無論如何,數據庫不會存儲文件。他們將URL存儲到文件中。 –
我嘗試傳遞soap參數中的文件,並且ajax請求無法識別我的方法,我認爲比我需要轉換爲二進制數組或字符串,但我沒有成功完成此操作。 –