post通过params上传base图片问题,el-upload上传时的跨域问题

需求:
我想通过chevereto图库提供的接口上传图片,图片source
请求例子是这样

POST http://mysite.com/api/1/upload/?key=12345&source=http://somewebsite/someimage.jpg

参数:
source:Either a image URL or abase64encoded image string. You can also use FILES["source"] in your request.
[官方调用api地址]:(https://chevereto.com/docs/ap...
上面说source支持base64,然后我将el-upload得到img转成base64编码,拼接到链接里

this.getBase64(file.raw).then(res => {
        this.actionUrl =
          "http://imgku.smacricketcvm.com/api/1/upload/?key=***&source=" +
          res;
      });

结果肯定是base64太大了然后报错了,请问怎么解决这个问题,计算机网络不过关。

image.png

补充问题:
下面是报错的代码
from origin 'http://localhost:8081' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

在vue。config中配置

"/upload": {
        target: "http://imgku.smacricketcvm.com/",
        ws: true,
        changOrigin: true,
        pathRewrite: {
          "^/upload": ""
        }

然后调用

this.getBase64(file.raw).then(res => {
        let i = res.indexOf(",");
        this.actionUrl =
          "/upload/api/1/upload/?key=04a0158b43738684594b638383145a63&source=" +
          res.substr(i + 1);
      });

结果还是会报上面的跨域问题,请问怎么解决

阅读 2.6k
1 个回答

image.png

前面这部分是 MIME,不是文件 Base64 结果的一部分,你得先去掉。从 /9j/... 开始才是 Base64。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题