我想将readstream文件传递给API,而不在本地下载,然后使用
fs
单元
下面是我的代码示例
const blobServiceClient = BlobServiceClient.fromConnectionString(
process.env.CONNEXION_STRING
);
const containerClient = blobServiceClient.getContainerClient(
params.containerName
);
const blobClient = containerClient.getBlobClient(process.env.PBIX_LOCATION);
let blobData;
try {
blobData = await blobClient.downloadToFile(`${params.reportName}.pbix`);
console.log(blobData);
} catch (error) {
console.log(error);
}
var options = {
method: "POST",
url: `https://api.powerbi.com/v1.0/myorg/groups/${params.groupId}/imports?datasetDisplayName=${params.reportName}`,
headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${params.accessToken} `,
},
formData: {
"": {
value: fs.createReadStream(`${params.reportName}.pbix`),
options: {
filename: `${params.reportName}.pbix`,
contentType: null,
},
},
},
};
//check if file keep in mem
return new Promise(function (resolve, reject) {
request(options, function (error, response) {
if (error) reject(error);
resolve(response.body);
fs.unlinkSync(`${params.reportName}.pbix`);
});
});
};
实际上,这段代码在本地运行,但在部署到azure功能时(可能是因为文件下载)。
我希望在不使用
downloadToFile
作用