简体   繁体   中英

Save file in MongoDB

I am with a problem with MongoDB, I have a Java SOAP web Service and my front is in Angular/Bootstrap/Jquery and I need save a file in my mongo database, but I have no idea how I do this, and I am trying this for 3 days, I need of an example with Jquery/js calling a SOAP service for do this or directly with js, I am receiving the file with <input type="file" id="file"/> . Thank you for your help. The type of my file is a tgz with a json and a image than I need save in my mongo database.

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>";

    }

My soap parameter is of the type java.io.File

Databases are meant to store data. You're probably not supposed to stick files (like images, etc.) straight into the database. Instead, upload the file to some storage server or a CDN and link to that from your database.

Then, you query the database, find the URL, and then fetch the resource from that URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM