将 Koa 应用部署到 Azure 应用服务后无法上传到 Azure 存储

时间:2021-03-04 10:15:39

标签: file-upload azure-web-app-service azure-storage-blobs koa koa-bodyparser

当应用在本地运行时,我可以将文件上传到 Azure Blob 存储。

但是当我将应用部署到 Azure 应用服务时,它总是响应 502 Bad Gateway

我使用库 koa-body 来处理上传文件

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);

我认为问题是我没有将文件写入 os.tmpDir() 的权限,所以我尝试转到 Kudu Debug Console 并将 chmod -R 0755 设置为 home/site/wwwroot/public/tmp,我认为文件夹是 os.tmpDir()。但它说我没有权限

感谢任何帮助

1 个答案:

答案 0 :(得分:0)

你可以参考我的示例代码。(Download my samle code)

enter image description here

enter image description here

测试结果。

POST 测试网址:https://yourappname.azurewebsites.net/user/upload

enter image description here

enter image description here

相关问题