如何在 Express 中使用 Croppie JS 和 Multer 中间件?

问题描述

我在前端使用以下代码上传图像并进行裁剪,然后再将其发送到使用 Expressjs 和 Multer 中间件编码的后端。我正在使用 croppieJs 库来裁剪图像。

$('.croppie-upload').on('click',function (ev) {
  croppieDemo.croppie('result',{
      type: 'canvas',size: 'viewport'
  }).then(function (image) {
    var imageBlob = image.split(",");
    console.log(imageBlob);
    var body = {
      sessionUserName: sessionStorage.getItem("userName"),profileImage : imageBlob[1]
    };
    fetch(instanceUrl + "/user_credentials/upload",{
      method: "PATCH",// POST,PUT,DELETE,etc.
      headers: {
        "Content-Type": "application/json",},body: JSON.stringify(body),})
      .then((response) => {
        if (response.status == 200) {
          response.json().then((data) => {
            if (data.updated === true) {
              doInit();
              alert("Saved Successfully!");
            }
          });
        }
      })
      .catch((err) => {});
  });
});

据我所知,问题是 Multer 接受 multipart/formdata 编码,而 croppie JS 提供 Base64 编码的字符串。 Express 抛出实体太大的错误。 有人能告诉我如何使用带有multer的croppie js吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)