上传图像时云无法解码base64(大小:1MB或更高)

发布于 2025-01-30 07:51:44 字数 1211 浏览 3 评论 0原文

我需要一些帮助,我正在研究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
    })
})

app.js

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

断爱 2025-02-06 07:51:44

Cloudinary SDK包含一种机制,该机制允许一定程度的网络公差,以促进大量文件上传。 上传大型方法将块中的大文件上传到云中,对于大于100 MB的文件是必需的。

对于您的实例,您可以尝试使用。您还可以按照云文档声明资源类型: https://cloudinary.com/document.com/documentation/upload_images/upload_images/upload_images #asset_types

const result = await 
cloudinary.v2.uploader.upload_large(imagesExterieur[i], {
     folder: 'MecArtToyota/imagesExterieur',
     chunk_size = 6000000
 });

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

const result = await 
cloudinary.v2.uploader.upload_large(imagesExterieur[i], {
     folder: 'MecArtToyota/imagesExterieur',
     chunk_size = 6000000
 });
谢绝鈎搭 2025-02-06 07:51:44

您需要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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文