【问题标题】:Storing assets in Apigee在 Apigee 中存储资产
【发布时间】:2014-10-31 02:30:37
【问题描述】:

我正在尝试将资产上传到 apigee baas,为此我遵循此处的文档: http://apigee.com/docs/api-baas/content/assets

这是我的代码:

    var querystring = require('querystring');

    var data = querystring.stringify({
        filename: 'car_123.jpg', //asset's name on Apigee
        file_location: 'http://cdn.xxxx.com/cars/123.jpg' //asset's original destination
    });

    var target_url = "https://api.usergrid.com/<org>/<app>/cars/<uuid>?access_token=dummyaccesstokenfor_SO"

    var options = {
        method: 'POST',
        url: target_url,
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': Buffer.byteLength(data)
        }
    };

    var request = require('request');

    request(options, function(err, data) {
        if (err) {
            console.log(err)
        } else {
            console.log('success')    
        };
    });

当我运行它时,我会收到一条成功消息。我想相信来自cdn的图像是物理的 复制到 Apigee 中。好像不是这样的

因为,当我发出 GET on https://api.usergrid.com/org/app/cars/uuid?access_token=dummyaccesstokenfor_SO 带有标题“Accept:image/jpeg”,我得到的只是这个

filename=cars_123.jpg&file_location='http://cdn.xxxx.com/cars/123.jpg

并且没有 base64 图像字符串或图像 url。

我哪里错了?

编辑:我在 BaaS GUI 中也看不到任何内容

EDIT2:根据 remus 的建议

curl -X POST -i -F name='apple-128' -F file=@"https://cdn4.iconfinder.com/data/icons/flat-brand-logo-2/512/apple-128.png" 'http://requestb.in/11xu3h61'

这导致

curl: (26) 无法打开文件“https://cdn4.iconfinder.com/data/icons/flat-brand-logo-2/512/apple-128.png

这里使用的 cdn 只是一个占位符。但是我的cdn的结果是一样的。因此,它甚至在 POST 之前就失败了。让我想知道文件位置是否可以是 http 位置?

【问题讨论】:

    标签: javascript node.js apigee


    【解决方案1】:

    您调用的端点应类似于 /{org}/{app}/{collection}/{entity uuid} 并带有 Accept: image/jpg 标头。此外,如果您查看 BaaS GUI,您应该会在那里看到带有文件详细信息和内容长度的实体。

    由于它仍然无法正常工作,这里有一个 CURL 命令可以正确上传资产:

    curl -X POST -i -F name='image' -F file=@"/path/to/image.jpg" 'https://api.usergrid.com/{org}/{app}/{collection}/{uuid}'
    

    您可以尝试针对requestbin 发布此 CURL 和您的 Node 方法并比较结果?

    【讨论】:

    • 我想 GET url 是由 SO 格式化的。它确实与您建议的名称相同。而且我在 BaaS GUI 中看不到任何内容
    • 嗯,有实体吗?还是集合是空的?
    • 有。集合 CARS 充满了汽车实体。现在我正在尝试向它们添加图像
    • 试过了 - 但它一起抛出了一个不同的错误。请检查 EDIT2
    • 啊,我明白了。我认为它不起作用,因为它没有下载文件。尝试做一个 request.pipe()?
    猜你喜欢
    • 1970-01-01
    • 2020-10-25
    • 1970-01-01
    • 2013-05-08
    • 1970-01-01
    • 2013-01-21
    • 2015-09-10
    • 2017-12-27
    • 2023-03-26
    相关资源
    最近更新 更多