当前位置: 首页 > 知识库问答 >
问题:

NodeJs API提供产品映像的目标路径

岑俊弼
2023-03-14

我正在上传一个产品的图像使用大商业API。API成功地创建了产品,但映像却没有。如何给出目标路径?

我给出了如下所示的目标路径

https://store-9gk124wgzn.mybigcommerce.com/dev/product_images

但这不起作用。

const storage = multer.diskStorage({
   destination: 'https://store-9gk124wgzn.mybigcommerce.com/dev/product_images',
   filename: function(req, file, cb) {
       cb(null, file.fieldname + '-' + Date.now() + path.extname(file.originalname));
   }
});

这里是完整的代码,我试图给出的路径图像,它已经把图像html" target="_blank">文件夹名buddha.jpg,但它没有通过图像。const productCreated=function(createnewproduct){console.log(createnewproduct);const deferred=q.defer();const postDataOptions={url:${BC_STORE_URL}/API/v2/products,method:“post”,headers:{“accept”:“application/json”,“content-type”:“application/json”,“authorization”:“basic”+new Buffer(BC_USER+“:”

app.post('/product-created', (req, res) => {

  const createnewproduct = {
    "name": req.body.name,
    "price": req.body.price,
    "categories": [req.body.categories],
    "type": req.body.type,
    "availability": req.body.availability,
    "description": "This timeless fashion staple will never go out of style!",
    "weight": req.body.weight,
    "is_visible": true,
    "id": 549

  };


  productCreated(createnewproduct).then(result => {
    const postImgDataOptions = {
      url: `${BC_STORE_URL}/api/v2/products/${result.id}/images`,
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Authorization': 'Basic ' + new Buffer(BC_USER + ':' + BC_TOKEN).toString('base64')
      },
      json: true,
      body: {
        //http://psdsandbox.com/022/pillow.jpg
        "image_file": "images/buddha.jpg", // this image is put in public folder
        "is_thumbnail": true,
        "sort_order": 0,
        "description": "Hi this is shutter img"
      }
    };
    request(postImgDataOptions, (error, response, body) => {
      console.log(response.statusCode);
      if (!error && response.statusCode == 201) {
        res.send('Done');
      } else {
        res.send('Bad Request');
      }
    });



  });

});

共有1个答案

施华奥
2023-03-14

您是否尝试只使用product_images/

而不是使用destination:https://...使用回调函数,如下所示

destination: function (req, file, cb) {
    cb(null, 'product_images/')
}

Update:所以要上传图像,您必须使用formdata

var uploadData = {
    image_file: {
      value: fs.createReadStream("images/buddha.jpg),
      options: {
        filename: "buddha.jpg",
        contentType: "image/jpg"
      }
    }
  };
  var uploadOptions = {
    method: "POST",
    uri: `${BC_STORE_URL}/api/v2/products/${result.id}/images`,
    formData: uploadData
  };
  return request(uploadOptions).then(res => {
    res.send('Done');
 }).catch(function(err){
    res.send('Bad Request');
 })
 类似资料:
  • 我正在从命令行自动化(python、boto3)产品的创建及其在服务目录中的发布。我创建产品,从响应中获取productId。然后,我使用列表启动路径拉入启动路径。当我最终开始设置产品时,我收到一个错误: 调用ProvisionProduct操作时发生错误(ResourceNotFoundException):找不到产品prod-vfwmgz65lckke。 我切换到使用aws cli,得到了相同

  • DaoCloud认为,在「互联网+」的时代,企业向互联网转型的入口是持续创新的「原力」,DaoCloud 基于容器技术打造了几大核心组件:DaoShip、DaoHub 和 DaoCloud,并通过这几大核心组件将持续创新的「原力」输送给企业,帮助企业实现互联网架构和业务的双转型。 核心产品模块 DaoShip 分布式持续集成流水线,通过类似工厂流水线的方式,自动化生产符合 Docker 环境的 A

  • 我有4张桌子: 库存(库存ID、可用数量) 一个客户可以有多个订单,而一个订单由多个orderDetails项目组成。我正在尝试将库存项目存储在由库存项目和数量整数组成的映射中。 当我尝试以这种方式持久化它时,第一个库存项目将以1的orderID添加到Order详细信息表中。但是下一个是使用2的orderID插入的(不存在)。 有什么帮助吗?

  • 我们运行一个Shibboleth身份提供者,越来越多的人要求我们使用非Shibboleth SAML解决方案与应用程序集成,并且在属性命名方面遇到了困难。用一个纯粹的Shibboleth IdP 我的问题是非Shibboleth服务提供商运营商,他们中的许多人拒绝重新映射IdP发送的属性,而是要求在IdP上定义新属性(携带现有属性中已有的值),使用服务提供商所有者指定的名称。这会导致IdP上的用户

  • 嗨,我刚刚开始在magento学习soap api。在本文中,我通过soap创建了一个产品,现在我想通过它分配产品图像。为此,我使用下面的代码 但我得到下面的错误致命错误:未捕获的SoapFault异常:[客户端]函数(调用)不是 /var/www/soap.php:19堆栈跟踪此服务的有效方法:#0 /var/www/soap.php(19):SoapClient- 请告诉我我哪里做错了。谢谢

  • 问题内容: 我在Docker网站上找到了这些信息 可以运行,启动,停止,移动和删除Docker容器。 据我所知,可以移动Docker映像,而不能移动Docker容器。但是上面的信息清楚地位于标题“ Docker容器”的下方。 因此,我想知道是否可以移动容器(如果不能移动,那么“ Docker容器可以移动”是什么意思)。 谢谢! 问题答案: 您可以使用 参见 https://docs.docker.