0
votes

I am able to successfully upload a file via an upload button to my vendors API. My vendors API also returns a .png file in blob format that I need to upload to Azure Blob Storage. I have tried a few approaches, but am getting the following error in my Node console:

[Error] statusCode: 414

My front end code is in an Angular Controller which passes data back to my Node backend that contains my Azure Blob Storage calls. I have the formidable and request modules installed and required, but am not using them in my current backend code since the data I receive is already in blob format.

Here is my front end upload code. The success "result" is the blob data I am returned:

$scope.sendToProduction = function () {
    var parts = document.getElementById("file").value.split("\\");
    var uploadedfilename = parts[parts.length - 1];
    var basefilename = uploadedfilename.split(".")[0];
    var fileextension = uploadedfilename.split(".")[1];
    var filename = basefilename + '.' + fileextension;
    var file = document.getElementById("file").files[0];

    var formdata = new FormData();
    formdata.append(filename, file);

    $.ajax({
        url: 'http://myvendorsapi/fileuploadendpoint',
        type: "POST",
        data: formdata,
        mimeType: "multipart/form-data",
        processData: false,
        contentType: false,
        crossDomain: true,

        success: function (result) {
            var filename = 'Test.png';
            var file = result;
            console.log(file);
            $http.post('/postAdvanced', {filename: filename, file: file }).success(function (data) {
                console.log(data);
            }, function (err) {
                console.log(err);
            });
        },

        error: function (error) {
            console.log("Something went wrong!");
        }
    });
};

Here is my node backend for uploading to Azure Blob Storage:

app.post('/postAdvanced', function (req, res, next) {
    var filename = req.body.filename;
    var file = req.body.file;

    blobSvc.createBlockBlobFromText('blob5', file, filename, function (error, result, response) {
        if (!error) {
            console.log("Uploaded" + result);
        }
        else {
            console.log(error);
        }
    });
})

How do I upload an AJAX response into Azure Blob Storage?

2

2 Answers

1
votes

The problem is that in this line of code:

blobSvc.createBlockBlobFromText('blob5', file, filename, function (error, result, response) {

you have the wrong parameter order. It should be:

blobSvc.createBlockBlobFromText('blob5', filename, file, function (error, result, response) {
1
votes

HTTP status code 414 means "Request-URI Too Long". Did you pass the correct blob name into blobSvc.createBlockBlobFromText?