Javascript 通过Ajax上传Shopify商品属性图像
是否可以使用Shopify通过Ajax上传商品属性图像?Shopify不允许通过Ajax上传文件Javascript 通过Ajax上传Shopify商品属性图像,javascript,ajax,shopify,Javascript,Ajax,Shopify,是否可以使用Shopify通过Ajax上传商品属性图像?Shopify不允许通过Ajax上传文件 我提出了一个使用Cloudinary(不直接上传到Shopify)的解决方案。我想我可以在这里分享。这是一个在Shopify中将图像作为行项目属性进行Ajax上传的解决方案 最初,我尝试将图像转换为BASE64,Ajax上载BASE64字符串。但是,这在显示整个BASE64字符串的顺序内起作用,而不是图像 于是,我转向了Cloudinary——一种图像上传服务。Cloudinary自动将BASE64
我提出了一个使用Cloudinary(不直接上传到Shopify)的解决方案。我想我可以在这里分享。这是一个在Shopify中将图像作为行项目属性进行Ajax上传的解决方案 最初,我尝试将图像转换为BASE64,Ajax上载BASE64字符串。但是,这在显示整个BASE64字符串的顺序内起作用,而不是图像 于是,我转向了Cloudinary——一种图像上传服务。Cloudinary自动将BASE64编码图像转换回“正确”图像 在Cloudinary中,我们需要启用未签名的图像上载,以使其正常工作 一旦启用,我们就可以将BASE64图像上传到Cloudinary
var data = {
upload_preset: "019au6h3", // the unsigned image preset within cloudinary
tags: "foo", // any tags you wish to apply
context: "photo=phototitle",
file: encodedImage // the BASE64 encoded image file http://stackoverflow.com/questions/6978156/get-base64-encode-file-data-from-input-form
}
// standard Jquery ajax post
jQuery.post("https://api.cloudinary.com/v1_1/dn5wucjj2/upload", data).done(function(data) {
// do something here
}).then(function(data) {
addToCart(data.secure_url) // addToCart is the ajax add to cart post function (whatever function your theme uses, modified to accept an the returned image)
});
data.secure\u url是图像上载后Cloudinary返回的url。然后我们可以将其传递给addToCart函数,该函数将产品添加到Shopify的购物车中
在结账时,客户将看到他们的图像的url(不理想)。然而,在后端,在订单中,Shopify将url转换为链接
对于那些关心安全的人: