vendredi 20 juillet 2018

How do I get bytearray from $.ajax response?

So, here's the deal. I need to download a zip file from an API and move it to another server. If I just type the url on the browser, it gives me the zip file I want, but I need this process to be automated, since I'm moving a lot of files.

So my question mainly is, is there a way to get this file as bytearray and post it to my server? My backend application is using ASP.NET MVC.

The code I currently have, but doesn't work, is this:

$.ajax({
    url: "https://api.mercadolibre.com/shipment_labels?shipment_ids=" + mlOrders[269].shipping.id + "&savePdf=Y&access_token=" + token,
    async: false,                                    
    success: function (zipFile) {
        console.log(zipFile);
        $.post(
            "/Home/GetPDF", { zipFile: zipFile },
            function () {
                alert('ok');
            }
        );
    },
    error: function (errorObject) {
        console.log("FILURE AT /orders/{id}/shipments ->", errorObject);
    }
});

It would be better if I could find a solution using jQuery, but not mandatory. Thanks in advance!




Aucun commentaire:

Enregistrer un commentaire