将图像文件附加到BigCommerce产品

时间:2017-09-19 04:41:33

标签: multipartform-data bigcommerce

BigCommerce API documentation表示图片文件可以通过API上传,而无需先将其上传到其他地方:

  

POST /catalog/products/{product_id}/images

     

在产品上创建图像。可公开访问的URL和文件(表单发布)是有效参数

强调我的。我的尝试,以下变化,大多数都是422 image_url must be present if uploading by url

curl -X POST \
  https://api.bigcommerce.com/stores/redacted/v3/catalog/products/123/images \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'x-auth-client: redacted' \
  -H 'x-auth-token: redacted' \
  -F productImage=@img_123.jpg \
  -F image_url=image_123.jpg

正确形成的请求是什么样的,POST是产品的图像文件?

相关:

1 个答案:

答案 0 :(得分:0)

A correctly formed request looks like this:

curl -X POST \
  https://api.bigcommerce.com/stores/js......7j/v3/catalog/products/32011/images \
  -H 'accept: application/json' \
  -H 'cache-control: no-cache'  \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'x-auth-client: ts2.........................r0r' \
  -H 'x-auth-token: ihq.........................5b2' \
  -F 'image_file=@Downloads/img_2405.jpg'

However, certain images can cause the misleading error; such as this one.

It's not clear what property of the file causes the error, but compressing or otherwise re-saving the image resolves the problem.