I am trying to upload assets to apigee baas for which I follow the docu in here: http://apigee.com/docs/api-baas/content/assets
Here is my code:
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')
};
});
When I run this, I get a success message. I want to believe that the image from the cdn is physically copied into Apigee. Seems that's not true
because, when I issue a GET on https://api.usergrid.com/org/app/cars/uuid?access_token=dummyaccesstokenfor_SO with header 'Accept:image/jpeg', all I get is this
filename=cars_123.jpg&file_location='http://cdn.xxxx.com/cars/123.jpg
And no base64 image string or image url.
Where am I going wrong?
EDIT: I don't see anything in the BaaS GUI either
EDIT2: As per remus's suggestion
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'
this results in
curl: (26) couldn't open file "https://cdn4.iconfinder.com/data/icons/flat-brand-logo-2/512/apple-128.png"
The cdn used here is just a place holder. But the result with my cdn is just the same. So, it is failing even before the POST. Makes me wonder if the file location can be a http location at all or not?
The endpoint you call should look like /{org}/{app}/{collection}/{entity uuid}
with the Accept: image/jpg header. Also if you look in the BaaS GUI, you should see the entity there with the file details and content length.
Since it's still not working, here's a CURL command that will properly upload the asset:
curl -X POST -i -F name='image' -F file=@"/path/to/image.jpg" 'https://api.usergrid.com/{org}/{app}/{collection}/{uuid}'
You could try POSTing both this CURL and your Node method against requestbin and compare the results?