我正在将图像从HTML画布上传到Cloudinary。以下代码正在运行,但是在Cloudiany服务器上创建了2个映像。
如果我只是直接从输入中上传图像(不使用画布),那么只会创建1张图像。
submit = async (e, mutation) => {
e.preventDefault();
const canvas = this.editor.getImage();
const data = new FormData();
data.append("file", canvas.toDataURL("image/jpg"));
data.append("upload_preset", "MYPRESET");
const res = await fetch(
"https://api.cloudinary.com/v1_1/CLOUDINARYID/image/upload",
{
method: "POST",
body: data
}
);
const file = await res.json();
const newImgUrl = file.secure_url;
const mutationRes = await mutation({
variables: {
id: this.props.me.id,
pic: newImgUrl
}
});
};