1

Following curl API is successfully deploying .zip file from the local file system into the Azure Function APP.

curl -X POST -u user123:P@ssword --data-binary @"C:\Ddrive\Porject\deploy-zip\wb-uc-code.zip" "https://abc-world.scm.azurewebsites.net/api/zipdeploy"

But I wanna achieve the same with NodeJs: So I converted it as -

function () {

var dataString = "@C:\Ddrive\Workbench\deploy-zip\wb-uc1.zip";

var options = {
    url: 'https://abc-world.scm.azurewebsites.net/api/zipdeploy',
    method: 'POST',
    body: dataString,
    auth: {
        'user': 'user123',
        'pass': 'P@ssword'
    }
};

request.post(options, (response, error) => {
    if (error) {
        console.log("error");
    }
    else {
        console.log(response.body);
    }
})

}

while executing am getting error: enter image description here ------->>> Most Probably I think am unable to provide file-path appropriately in Options. Can someone help with this?

Tony Ju
  • 14,891
  • 3
  • 17
  • 31

1 Answers1

1

There are two things you need to pay attention to.

1.You should pass data-binary, you were passing path string in your code.

2.The order of response and error is reversed.

Please refer to the working code as below.

var request=require('request')
var fs = require("fs")

var dataString=fs.createReadStream("D:\\testProject\\NodeJs\\nodejs-docs-hello-world\\test4.zip");

var options = {
    url: 'https://tonytestwebnode.scm.azurewebsites.net/api/zipdeploy',
    method: 'POST',
    body: dataString,
    auth: {
        'user': 'tonytestweb',
        'pass': 'XXXX!'
    }
};

request.post(options, (error, response) => {
    console.log(response.statusCode);
})
Tony Ju
  • 14,891
  • 3
  • 17
  • 31
  • Thanks for your help, That error got resolved but deployment was unsuccessful, I am getting 500 error code but the same is getting deployed with curl. – G KAMESWAR RAO May 16 '20 at 11:30
  • @GKAMESWARRAO What is the detailed error message? Is the password correct? – Tony Ju May 16 '20 at 12:00
  • Yes I checked file-path it is correct and I believe your code is also correct. Are you able to deploy the file in Azure AppService? Am trying to deploy function App through this URL, though it gets deployed by curl while trying to achieve the same with Node am getting an issue. – G KAMESWAR RAO May 16 '20 at 12:01
  • @GKAMESWARRAO Yes, I deployed an webapp successfully. You need to check the detailed error message. – Tony Ju May 16 '20 at 12:02
  • Am getting the following error: 500 BODY: --> {"Message":"An error has occurred.","ExceptionMessage":"End of Central Directory record could not be found.","ExceptionType":"System.IO.InvalidDataException","StackTrace":" at System.IO.Compression.ZipArchive.ReadEndOfCentralDirectory()\r\n at System.IO.Compression.ZipArchive.Init(Stream stream, ZipArchiveMode mode, Boolean leaveOpen)\r\n at System.IO.Compression.ZipArchive..ctor(Stream stream, ZipArchiveMode mode, Boolean leaveOpen, Encoding entryNameEncoding)\r\n at Kudu.Services.Deployment.Pu\ – G KAMESWAR RAO May 16 '20 at 12:03
  • 1
    @GKAMESWARRAO Please check this link https://stackoverflow.com/questions/20960403/end-of-central-directory-record-could-not-be-found – Tony Ju May 16 '20 at 12:07