0

Trying to find a solution for storing some files from a lil' app I'm currently building, I tried to use a filepicker node module and tried the simplest example I could create:

app.get('/test', function(req, res) {
  fs.readFile('myFile.txt', function (err, buf){
      filepicker.getUrlFromBuffer(buf, {persist: true}, function (err, url) {
          console.log("myfile.txt is now stored at " + url);
      });
      return res.send('something');
  });

I get this error message : "TypeError: Cannot read property 'url' of undefined". But when I check the console on filepicker.io site, I can see that the file has been uploaded.

Here is the github repo I got the filepicker node module from: https://github.com/treygriffith/filepicker/blob/master/README.md

Thank you guys!

hypervillain
  • 393
  • 1
  • 5
  • 18

1 Answers1

1

Most likely filepicker.io changed their API since that module was last updated (2012). Here is documentation for their current REST API which should be easy enough to use manually with a module like request to upload the file. Example:

var request = require('request');
var FILEPICKER_API_KEY = 'foobarbaz';

var formData = {
      fileUpload: fs.createReadStream(__dirname + '/unicycle.jpg')
    },
    cfg = {
      url: 'https://www.filepicker.io/api/store/S3?key=' + FILEPICKER_API_KEY,
      formData: formData
    };
request.post(cfg, function(err, res, body) {
  if (err)
    return console.error('upload failed:', err);
  var response;
  try {
    response = JSON.parse(body);
  } catch (ex) {
    console.log(ex);
  }
  if (response)
    console.dir(response);
});
mscdex
  • 104,356
  • 15
  • 192
  • 153
  • Didn't pay attention to the last commit date, thank you both for pointing it out. Thank you for this sample code too, I'll give it a try as soon as possible ! – hypervillain Oct 03 '14 at 15:25