Elvin Mammadov
Elvin Mammadov

Reputation: 17

Azure "blobService is not defined" error with NodeJS

Here is my node codes in order to connect Azure Blob Storage and upload base64 photo to recieve url link for the photo. Codes are based on Azure tutorial but somehow my AccountName and AccountKey fails. I could not figure out how to set up my createBlobService variable.My AccountName and AccountKey's are just simple strings ie. "Product", "Base64KeyProvidedByAzure"

Any help please?

Account name, account key and container names are just dummy strings here.

var blobSvc = azure.createBlobService('AccountName', 'AccountKey');


        blobService.createContainerIfNotExists('containerName', {
            publicAccessLevel: 'blob'
        }, function(error, result, response) {
            if (!error) {
                // if result = true, container was created.
                // if result = false, container already existed.
                var sharedAccessPolicy = {
                    AccessPolicy: {
                        Permissions: azure.BlobUtilities.SharedAccessPermissions.WRITE,
                    }
                };
                var sharedAccessSignatureToken = blobSvc.generateSharedAccessSignature('ContainerName', req.params.filename, sharedAccessPolicy);
                var sharedBlobService = azure.createBlobServiceWithSas(blobSvc.host, sharedAccessSignatureToken);

                sharedBlobService.createBlockBlobFromText('eats', req.params.name, req.params.file,
                    {
                        contentType: 'image/jpeg',
                        contentEncoding: 'base64'
                    },

                    function(error, result, response) {
                    if (error) {
                        res.send(error);
                        return;
                    }


                    var msg = "Photo Uploaded successfully";
                    helpers.success(res, next, msg, 200);
                    return next();
                });
            }
        });

Upvotes: 0

Views: 2376

Answers (1)

Gary Liu
Gary Liu

Reputation: 13918

You create a blob service instance and assign to blobSvc in line 1:

var blobSvc = azure.createBlobService('AccountName', 'AccountKey');

However, you used blobService to call functions in SDK. So it threw blobService is not defined exception.

Upvotes: 2

Related Questions