0

I have a frontend which sends the HTML of that page to a Node.js server. The server should then send that HTML to Azure BlobStorage.

Here is my express route to handle this:

router.post("/sendcode", function(req, res) {
  let code = "";
  code = req.body.code;
  console.log(code);
  let service = storage.createBlobService(process.env.AccountName, process.env.AccountKey);
  service.createContainerIfNotExists("htmlcontainer", function(error, result, response) {
    if (error) {
      throw error;
    } else {
      service.createBlockBlobFromStream("htmlcontainer", code, function(err, result, response) {
        if (err) {
          throw err;
        } else {
          console.log(result);
          console.log(response);
        }
      });
    }
  });
});

When I call this route, I receive this in my console:

<html><style>* { box-sizing: border-box; } body {margin: 0;}</style><body></body></html>

How can I send it to BlobStorage? Avoid the method I used as it maybe wrong because I can't figure out what function to use because of scarce documentation.

Rick
  • 4,030
  • 9
  • 24
  • 35
Barry Bonds
  • 118
  • 2
  • 11

2 Answers2

0

There are many answers on stack overflow, you can follow this one and adjust it to your needs: Uploading a file in Azure File Storage using node.js

Mor Shemesh
  • 2,689
  • 1
  • 24
  • 36
0

So after trying a little bit, i was able to send it not from stream but after writing it to a file, sending that file through createBlockBlobFromLocalFile function in azure-storage module and deleting the file from disk.

I know this isnt the most efficient method out there but it got my work done.

The problem i was facing was that after uploading html code in a block blob(without file operation), its content type was application/octet which i wanted to be text/html. So i had to perform one more operation to change its content type, which i found to be a little difficult due to unavailability of documentation and examples in javascript.

Barry Bonds
  • 118
  • 2
  • 11