I have a function that should upload a file to Azure. The code is pretty much copied right from the sdk docs, except for a couple of log statements:let saveToAzure = async function (file, fileName) {const account = 'xyz'const accountKey = 'xyz'const sharedKeyCredential = new Azure.SharedKeyCredential(account, accountKey)const serviceClient = new Azure.FileServiceClient(`https://${account}.file.core.windows.net`,sharedKeyCredential)const shareName = `newshare${new Date().getTime()}`const shareClient = serviceClient.getShareClient(shareName)await shareClient.create()console.log(`Create share ${shareName} successfully`)const directoryName = `newdirectory${new Date().getTime()}`const directoryClient = shareClient.getDirectoryClient(directoryName)await directoryClient.create()console.log(`Create directory ${directoryName} successfully`)const content = fileconsole.log(JSON.stringify(content) + ' || content')const azureFileName = fileName + new Date().getTime()const fileClient = directoryClient.getFileClient(azureFileName)console.log(JSON.stringify(fileClient) + ' || fileClient')await fileClient.create(content.length)console.log(`Create file ${azureFileName} successfully`)// Upload file rangeawait fileClient.uploadRange(content, 0, content.length)console.log(`Upload file range "${content}" to ${azureFileName} successfully`)}When this file is called, the client is created and the directory is created. I get both of the log statements that I should: Create share newshare1568422802286 successfullyand Create directory newdirectory1568422802618 successfully. But after that, nothing happens. A file is never created, and no content is uploaded to the file.For reference, here is where the saveToAzure function is being called. The file upload was processed with multer:exports.create = function (req, res) {let firmware = {name: req.body.name,version: req.body.version,description: req.body.description,date: req.body.date}firmwareRepo.create(firmware, (err, create) => {if (err) {console.log(err)return res.status(500).send({error: 'Unable to create firmware!'})} else {return res.status(200).send({success: 'Firmware created!'})}})saveToAzure(req.file, req.body.name)}What is going on that only the first half of the Azure code is working properly?
Submitted September 14, 2019 at 03:40PM by Briyo2289
No comments:
Post a Comment