i have problem downloading files ibm bluemix object storage using nodejs script, problem takes long time download file storage, 100k file takes around 21 seconds, around 8 seconds waiting first chunk , rest reading chunks
i using service store images , using nodejs script read these images storage, , images downloaded via html img tag, doing wrong here ?
the nodejs code:
app.get("/ostore/image/:filename", function(request, response) { response.set('content-type', 'image/jpg'); response.set('cache-control', 'max-age=604800'); response.set('last-modified', 'sat, 05 dec 2015 03:17:48 gmt'); var credentials = app.appenv.services['object-storage'][0].credentials var pkgcloud = require("pkgcloud"); var client = pkgcloud.storage.createclient({ provider: 'openstack', username: credentials.userid, password: credentials.password, authurl: credentials.auth_url, tenantid: credentials.projectid, region: credentials.region, version: "2" }); client.download({ container: app.storagecontainer, remote: request.params.filename, stream: response }, function() { response.end('done'); }); });
try this:
routes.js
var vcap_os = require(__dirname + '/../utils/vcap')('object-storage'), os = require(__dirname + '/../modules/object-storage'); module.exports = function(app) { var router = app.loopback.router(); // proxy object storage service router.get('/api/products/image/:container/:file', function(req, res) { os(vcap_os.credentials).download(req.params.container, req.params.file, function(download) { download.pipe(res); }); }); app.use(router); }
modules/object-storage.js
var pkgcloud = require('pkgcloud'); module.exports = function(creds) { var config = { provider: 'openstack', useservicecatalog: true, useinternal: false, keystoneauthversion: 'v3', authurl: creds.auth_url, tenantid: creds.projectid, domainid: creds.domainid, username: creds.username, password: creds.password, region: creds.region }; return { download: function(container, file, cbk) { var client = pkgcloud.storage.createclient(config); client.auth(function (error) { if(error) { console.error("authorization error storage client (pkgcloud): ", error); } else { var request = client.download({ container: container, remote: file }); cbk(request); } }); } }; };
Comments
Post a Comment