【发布时间】:2021-03-21 06:40:48
【问题描述】:
我正在尝试使用 nodejs 将从我创建的仪表板中选择的图像上传到 Cloudinary。我在这方面遇到了一些麻烦,因为我需要允许用户基本上从他们的计算机中选择任何图像并上传它,而不用硬编码它将进入的文件夹路径。我现在设置它的方式只让我选择我的计算机中具有指定路径的文件。我的前端非常简单:
<label for="image">SELECT IMAGE</label>
<input type="file" name="image" id="fileUploader" required/>
我的后端直接来自 Cloudinary,进行了一些简单的修改以适应我现有的代码,该代码将图像 url 上传到 DB2(sql db):
app.get('/addProducts', (req, res) => {
if (userAuth == 'true') {
var path = require('path')
// collected image from a user
const data = {
image: req.query.image,
}
console.log(data.image)
// upload image here
cloudinary.uploader.upload(data.image)
.then((result) => {
console.log(result.secure_url)
(sql) ......
这一行cloudinary.uploader.upload(data.image) 将导致出现关于找不到路径的错误。一旦我将它放入代码行 cloudinary.uploader.upload('./public/css/img/ + data.image) 它就可以工作。这不可能发生,因为正如我之前所说,它不允许任何用户从本地计算机中选择图像并上传。
感谢您的帮助。
【问题讨论】:
标签: html node.js cloud cloudinary