上传图像时云无法解码base64(大小:1MB或更高)
我需要一些帮助,我正在研究React应用程序,我在使用Mern堆栈上将照片上传到Cloudinary上很难“无法解码base64” 注意:我目前正在使用免费版本。
exports.newProduct = catchAsyncErrors(async (req, res, next) => {
let imagesExterieur = [];
// handle images external
if (typeof req.body.imagesExterieur === 'string') {
imagesExterieur.push(req.body.imagesExterieur)
} else {
imagesExterieur = req.body.imagesExterieur
}
let imagesExterieurLinks = [];
for (let i = 0; i < imagesExterieur.length; i++) {
const result = await cloudinary.v2.uploader.upload(imagesExterieur[i], {
folder: 'MecArtToyota/imagesExterieur'
});
imagesExterieurLinks.push({
public_id: result.public_id,
url: result.secure_url
})
}
req.body.imagesExterieur = imagesExterieurLinks;
req.body.user = req.user.id;
const product = await Product.create(req.body);
res.status(201).json({
success: true,
product
})
})
I need some help ,I am working on the React app, I'm having trouble uploading photos to Cloudinary using MERN stack "Could not decode base64"
Note: I am currently using the free version.
exports.newProduct = catchAsyncErrors(async (req, res, next) => {
let imagesExterieur = [];
// handle images external
if (typeof req.body.imagesExterieur === 'string') {
imagesExterieur.push(req.body.imagesExterieur)
} else {
imagesExterieur = req.body.imagesExterieur
}
let imagesExterieurLinks = [];
for (let i = 0; i < imagesExterieur.length; i++) {
const result = await cloudinary.v2.uploader.upload(imagesExterieur[i], {
folder: 'MecArtToyota/imagesExterieur'
});
imagesExterieurLinks.push({
public_id: result.public_id,
url: result.secure_url
})
}
req.body.imagesExterieur = imagesExterieurLinks;
req.body.user = req.user.id;
const product = await Product.create(req.body);
res.status(201).json({
success: true,
product
})
})
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Cloudinary SDK包含一种机制,该机制允许一定程度的网络公差,以促进大量文件上传。
上传大型
方法将块中的大文件上传到云中,对于大于100 MB的文件是必需的。对于您的实例,您可以尝试使用。您还可以按照云文档声明资源类型: https://cloudinary.com/document.com/documentation/upload_images/upload_images/upload_images #asset_types
The Cloudinary SDKs contain a mechanism that allows for a degree of network tolerance in order to facilitate the upload of huge files. The
upload large
method uploads a big file in chunks to the cloud and is necessary for files larger than 100 MB.For your instance you can try this. You can also declare the resource type as per the cloudinary documentation : https://cloudinary.com/documentation/upload_images#asset_types
您需要URL逃脱整个base64输入字符串。因此,例如,如果您的base64字符串以:
数据:image/jpeg; base64
开头,则应为:data%3aimage%2FJPEG%3BBASE64%2C
。You need to URL escape your whole Base64 input string. So for example, if your Base64 string starts with:
data:image/jpeg;base64
, it should be:data%3Aimage%2Fjpeg%3Bbase64%2C
.