1

I've started a build of a custom adapter for Skipper in Sails.js using pkgcloud to upload to Rackspace cloud files, but I've gotten stuck. It doesn't appear that the file is actually getting uploaded and trying to capture the error doesn't seem to work. Maybe I'm missing something.

I've posted my code here: https://github.com/ccoppenbarger/skipper-rackspace

You would need to check it out in api/adapters/rackspace to use it.

I'm only working on the receiver part for now. The pkgcloud api is here: https://developer.rackspace.com/docs/cloud-files/getting-started/

My controller code is as follows:

upload : function(req, res){
               
        req.file('file').upload({
          adapter: require('../adapters/rackspace/index'),
          username: sails.config.rackspace.username,
          apiKey: sails.config.rackspace.apiKey,
          region: sails.config.rackspace.region,
          container: sails.config.rackspace.container
        }, function whenDone(err, uploadedFiles) {
          if (err) return res.negotiate(err);
          else return res.ok({
            files: uploadedFiles,
            textParams: req.params.all()
          });
        });
    },

Can someone take a look and see what I may be missing in the index.js?

  • 1
    Can you confirm you're using the latest example from our help docs? https://developer.rackspace.com/docs/cloud-files/getting-started/#upload-objects-to-container also what version of pkgcloud? – Ken Perkins Mar 24 '15 at 18:09
  • Yes, I'm using that version of your help docs, although I've had to modify it to work with Skipper. Also, using 1.2.0 alpha of pkgcloud. – Chris Coppenbarger Mar 24 '15 at 18:39
  • It looks like this line https://github.com/ccoppenbarger/skipper-rackspace/blob/master/index.js#L98 is incorrect, shouldn't it be `outs__.once('success', function() {});` instead of `outs.once('finish', function() {});`? – Ken Perkins Mar 24 '15 at 19:19
  • Well, it should at least be outs__.once.... I did have to change that. That change is on my local disk, not committed yet, but finish is correct. – Chris Coppenbarger Mar 24 '15 at 19:38
  • We don't use finish in pkgcloud, we use success, that's part of why I asked. – Ken Perkins Mar 24 '15 at 19:46
  • @ChrisCoppenbarger looks like you need to use the 'success' event instead of 'finish' – mikermcneil Mar 25 '15 at 02:56
  • It looks like what I have is working, I did a hit on the container and observed that there are objects in there. It does not matter whether I use success or finish. Basically, what I've posted is working. I just need to explore the Rackspace API more. When I'm done, we'll have another adapter for skipper at least. – Chris Coppenbarger Mar 25 '15 at 17:26

2 Answers2

0

Just to answer this question myself, my code was working, but the issue was that I was expecting one CDNUri, but was getting something else. Basically, my receiver code works. Now I just need to finish out for others to be able to use with Skipper as well.

  • I need to add that I had to remove the github repository due to some internal IP concerns with a client. A public repository will likely be posted in the future once product launches for the skipper-rackspace adapter. If anyone would like help on using this, I'd be glad to help, but have to be careful because of IP use. – Chris Coppenbarger Mar 26 '15 at 17:22
0

No source found, this example of adapter using pkgcloud

 function pkgCloudReceiver(opts){

    var receiver__ = Writable({
      objectMode: true
    });

    var client = getClientStorage(options);

    receiver__.once('error', function(err){
      //console.log('once err',err);
    });

    receiver__._write = function(__newFile, encoding, next){
      options.tmpdir = options.tmpdir || path.resolve(process.cwd(), '.tmp/pkgcloud-temp');

      var file = {
        container: options.container,
        remote: __newFile.fd,
        contentType: mime.lookup(__newFile.fd),
      };

      writeStream = client.upload(file);

      writeStream.on('error', function(err){
        receiver__.emit('error', err);
      });

      writeStream.on('progress', function(data){
        //console.log('progress', data);
      });

      writeStream.on('success', function(data){
        next();
      });

      __newFile.pipe(writeStream);

    };

    return receiver__;

  };

complete adapter: https://github.com/urielaero/skipper-pkgcloud

Uriel
  • 129
  • 3