I got most of the code from the NodeJS Blob quickstart from azure, I am able to upload files including images successfully and I can see them in the azure storage dashboard just fine. But I can't seem to download them or get a URL to them and I need the url for my database so I can query it and use the url to retrieve the file.
The download part of the code in the quickstart isnt so clear …
azure-storage azure-storage-blobs node.js azure-blob-storage
我尝试了几种不同的方法,基本上我想从路由中取出cloudinary上传代码,并将其放入路由调用的函数中,以使代码更简洁。但是出于某种原因,我无法让异步/等待工作/等待上传完成才能完成。
这是我的路线示例:
var fieldsUpload = upload.fields([{ name: 'image1', maxCount: 1 }, { name: 'image2', maxCount: 1 }])
router.post('/upload', fieldsUpload, async function (req, res, next) {
var url1 = await uploadToCloudinary(req.files['image1'][0].path);
console.log("Cloudinary url: " + url1);
var url2 = await uploadToCloudinary(req.files['image2'][0].path);
console.log("Cloudinary url: " + url2);
res.send("Succesfull Upload");
});
Run Code Online (Sandbox Code Playgroud)
这是我的功能:
async function uploadToCloudinary(image) {
try{
let url = await cloudinary.v2.uploader.upload(image);
}
catch(err){ console.log(err)}
}
// function uploadToCloudinary(image) {
// cloudinary.v2.uploader.upload(image, function(error, result) {
// if(error) {
// console.log(error);
// }
// …Run Code Online (Sandbox Code Playgroud) 我似乎无法找到为什么会发生这种情况,我在大多数应用程序中都有几乎相同的代码,它几乎是样板,我只是试图将 HTML 的顶部分成 header.ejs 并将底部分成一个footer.ejs 文件,然后将它们包含到我的 index.ejs 中。当我将所有代码保存在 index.ejs 文件中时,它很好。我也试过删除这样的空格 <%include ./partials/header.ejs%>,添加'-' <%- include ./partials/header.ejs %>,即使我有这个错误,我仍然收到这个错误相同的代码 - 我的文件中的相同语法。
<% include ./partials/header.ejs %>
<h1>YO HO HO LET THIS WORK!</h1>
<% include ./partials/footer.ejs %>
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>P2</title>
<link rel="stylesheet" href="/stylesheets/app.css">
</head>
<body>
Run Code Online (Sandbox Code Playgroud)
</body>
</html>
Run Code Online (Sandbox Code Playgroud)