score:1

Accepted answer

I used this and it worked. below is server side code(NodeJS)

var contentType = 'image/jpeg';
    let base64String=req.body.img;
    let base64Image = base64String.split(';base64,').pop();
    let date=Date.now();
    fs.writeFile(`./uploads/${date}.jpeg`, base64Image, {encoding: 'base64'}, function(err) {
    console.log('File created');
    sourceFilePath= path.resolve(`./uploads/${date}.jpeg`);
   blobName=path.basename(sourceFilePath, path.extname(sourceFilePath));
   //console.log(sourceFilePath);
    blobService.createBlockBlobFromLocalFile(containerName, blobName, sourceFilePath, err => {
            if (err) {
                console.log(err);
            } 
            else {
                //resolve({ message: `Upload of '${blobName}' complete` });
                console.log("UPLOADED")
            }
        });

score:-2

Hi i use this function

public b64toBlob = (b64Data: string = '', sliceSize?: number) => {
            sliceSize = sliceSize || 512;
            if ( b64Data !== null) {
                let block = b64Data.split(';');
                let dataType = block[0].split(':')[1];
                let realData = block[1].split(',')[1];
                let filename = this.makeid() + '.' + dataType.split('/')[1];
                let byteCharacters = atob(realData);
                let byteArrays = [];
                for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {
                    let slice = byteCharacters.slice(offset, offset + sliceSize);

                    let byteNumbers = new Array(slice.length);
                    for (let i = 0; i < slice.length; i++) {
                        byteNumbers[i] = slice.charCodeAt(i);
                    }
                    let byteArray = new Uint8Array(byteNumbers);
                    byteArrays.push(byteArray);
                }
                let blob = new Blob(byteArrays, {type: dataType});
                return blob ;
            } else {
                return '';
            }
        }

score:-1

Try this:

  1. based-blob

    (async function() {
      const b = require('based-blob');
    
      const base64String = 'some base64 data...';
    
      const blob = b.toBlob(base64String);
      const b64s = await b.toBase64(blob);
    
      console.log(b64s == base64String); // true
    })();
    

score:4

You can convert your Base64 string to Buffer and then try storing it to azure.

var base64String = "....."; // your base64 string
var bufferValue = Buffer.from(base64String,"base64");

Related Query

More Query from same tag