file-uploadazure-web-app-serviceazure-blob-storagekoakoa-bodyparser

Can't upload to Azure Storage after deploy Koa app to Azure App Service


When App run on local, I can upload file to Azure Blob Storage.

But when I deploy app to Azure App Service, it always responses 502 Bad Gateway

I use library koa-body to handle upload file

const koaBody = require('koa-body')({ multipart: true, uploadDir: '.' });
const blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING);
const videoContainerClient = blobServiceClient.getContainerClient(AZURE_VIDEO_STORAGE_CONTAINER);
const blobVideoName = `${fileName}.${fileExtension}`;
const blockBlobVideo = videoContainerClient.getBlockBlobClient(blobVideoName);
const uploadVid = blockBlobVideo.uploadFile(filePath);

I think the problem is I don't have permission to write file to os.tmpDir(), so I try to go to Kudu Debug Console and set chmod -R 0755 to home/site/wwwroot/public/tmp, the folder I think is os.tmpDir(). But it said I don't have permission

Any help is appreciated


Solution

  • You can refer to my sample code.(Download my samle code)

    enter image description here

    enter image description here

    Test Result.

    POST test url : https://yourappname.azurewebsites.net/user/upload

    enter image description here

    enter image description here