You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have configure all credential for upload file and save in Bluemix Object Storage with the help this solution, code here
...
...
var pkgcloud = require('pkgcloud-bluemix-objectstorage');
var fs = require('fs');
app.post('/upload', function(req, res) {
// Create a config object
var config = {};
// Specify Openstack as the provider
config.provider = "openstack";
// Authentication url
config.authUrl = 'https://identity.open.softlayer.com/';
config.region= 'dallas';
// Use the service catalog
config.useServiceCatalog = true;
// true for applications running inside Bluemix, otherwise false
config.useInternal = false;
// projectId as provided in your Service Credentials
config.tenantId = '234567890-0987654';
// userId as provided in your Service Credentials
config.userId = '098765434567890';
// username as provided in your Service Credentials
config.username = 'admin_34567890-09876543';
// password as provided in your Service Credentials
config.password = 'sdfghjklkjhgfds';
//This is part which is NOT in original pkgcloud. This is how it works with newest version of bluemix and pkgcloud at 22.12.2015.
//In reality, anything you put in this config.auth will be send in body to server, so if you need change anything to make it work, you can. PS : Yes, these are the same credentials as you put to config before.
//I do not fill this automatically to make it transparent.
config.auth = {
forceUri : "https://identity.open.softlayer.com/v3/auth/tokens", //force uri to v3, usually you take the baseurl for authentication and add this to it /v3/auth/tokens (at least in bluemix)
interfaceName : "public", //use public for apps outside bluemix and internal for apps inside bluemix. There is also admin interface, I personally do not know, what it is for.
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"id": "098765434567890", //userId
"password": "sdfghjklkjhgfds" //userPassword
}
}
},
"scope": {
"project": {
"id": "234567890-0987654" //projectId
}
}
};
//console.log("config: " + JSON.stringify(config));
// Create a pkgcloud storage client
var storageClient = pkgcloud.storage.createClient(config);
// Authenticate to OpenStack
storageClient.auth(function (error) {
if (error) {
console.error("storageClient.auth() : error creating storage client: ", error);
} else {
//OK
var new_fname = dir + "__" + file.originalname;
var readStream = fs.createReadStream('uploads/' + file.filename);
var writeStream = storageClient.upload({
container: 'chat-files',
remote: new_fname
});
writeStream.on('error', function(err) {
// handle your error case
console.log("concluido o upload com erro!");
console.log(err);
});
writeStream.on('success', function(file) {
// success, file will be a File model
console.log("concluido o upload com sucesso!");
});
readStream.pipe(writeStream);
}
});
}
...
...
But when i hit this api using postman then it throw an error i.e,
ERR TypeError: Cannot read property 'passwordCredentials' of undefined
2016-05-19T17:04:28.81+0530 [App/0] ERR at Client._getIdentityOptions (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud/openstack/client.js:96:49)
2016-05-19T17:04:28.81+0530 [App/0] ERR at exports.Client (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud/openstack/client.js:64:46)
2016-05-19T17:04:28.81+0530 [App/0] ERR at new exports.Client (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud/openstack/storage/client/index.js:21:20)
2016-05-19T17:04:28.81+0530 [App/0] ERR at new exports.createClient (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud/openstack/storage/index.js:14:10)
2016-05-19T17:04:28.81+0530 [App/0] ERR at Object.pkgcloud.(anonymous function).createClient (/home/vcap/app/node_modules/pkgcloud-bluemix-objectstorage/lib/pkgcloud.js:97:12)
2016-05-19T17:04:28.81+0530 [App/0] ERR at /home/vcap/app/app.js:55:40
2016-05-19T17:04:28.81+0530 [App/0] ERR at Layer.handle [as handle_request] (/home/vcap/app/node_modules/express/lib/router/layer.js:95:5)
2016-05-19T17:04:28.81+0530 [App/0] ERR at next (/home/vcap/app/node_modules/express/lib/router/route.js:131:13)
2016-05-19T17:04:28.81+0530 [App/0] ERR at Route.dispatch (/home/vcap/app/node_modules/express/lib/router/route.js:112:3)
2016-05-19T17:04:28.81+0530 [App/0] ERR at Layer.handle [as handle_request] (/home/vcap/app/node_modules/express/lib/router/layer.js:95:5)
The text was updated successfully, but these errors were encountered:
I have configure all credential for upload file and save in Bluemix Object Storage with the help this solution, code here
The text was updated successfully, but these errors were encountered: