Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

upload file on node js azure function

const streamifier = require('streamifier');
const multipart = require('parse-multipart');
const azure = require('azure-storage');

module.exports =  function (context, req) {
  var bodyBuffer = Buffer.from(req.body);
  var boundary = multipart.getBoundary(req.headers['content-type']);
  var parts = multipart.Parse(bodyBuffer, boundary);

  var filedata = parts[0].data;         // Image buffer data
  var filename = parts[0].filename;     // testImage.png
  console.log("parts[0].data");
  console.log(parts[0].data);
  console.log("parts[0].filename");
  console.log(parts[0].filename);
  const accountname ="blobstorage0516";
  const key = "eGier5YJBzr5z3xgOJUb+sn***7Csvgx75NwiOZE7kYLJfLqWBg==";
  const containerName="test1";
  const blobClient  =azure.createBlobService(accountname,key);
 # set blob content type
  var options = {
    contentSettings:{contentType: parts[0].type}
  };
  blobClient.createBlockBlobFromStream(containerName,filename,streamifier.createReadStream(new Buffer(filedata)), filedata.length,options,(err,result)=>{

    if (!err) {
        console.log("Image upload successful", result);

    } else{

      throw err;
    }
  })
  context.res = {
    // status defaults to 200 */
    body: "ok"
};
context.done();
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: signed and unsigned integers in JavaScript 
Javascript :: convert nested json to csv python 
Javascript :: using python with javascript 
Javascript :: discord.js reason 
Javascript :: how to calculate bmi 
Javascript :: xmlhttprequest object 
Javascript :: json to string 
Javascript :: nodejs sql syntax 
Javascript :: tailwindcsss next js change font 
Javascript :: pass array from controller to javascript blade 
Javascript :: compare strings js 
Javascript :: mail 
Javascript :: expression vs statement javascript 
Javascript :: boucle foreach js 
Javascript :: Simple interest in javascript 
Javascript :: javascript basic function 
Javascript :: performing query with sequelize includes 
Javascript :: salvar no localStorage react 
Javascript :: iframe url redirect 
Javascript :: jquery repeater 
Javascript :: how to convert decimal to roman in javascript 
Javascript :: js reduce 
Javascript :: Using json_encode() function to convert an Array to a string 
Javascript :: array of obj to obj with reduce 
Javascript :: javascript arreglos 
Javascript :: node js add new object to object array json 
Javascript :: super method in js 
Javascript :: laravel vue global function 
Javascript :: what is javascript runtime 
Javascript :: discord.js if no arguments 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =