From: Girish Ramakrishnan Date: Fri, 27 Nov 2015 23:01:36 +0000 (-0800) Subject: Display uploaded URL X-Git-Url: https://git.immae.eu/?a=commitdiff_plain;ds=sidebyside;h=0f5a7ba229422f25a65e07d65b4768b9ad455a12;p=perso%2FImmae%2FProjets%2FNodejs%2FSurfer.git Display uploaded URL --- diff --git a/cli/actions.js b/cli/actions.js index 7767281..e5b0c6d 100644 --- a/cli/actions.js +++ b/cli/actions.js @@ -94,10 +94,15 @@ function put(filePath, otherFilePaths, options) { async.eachSeries(files, function (file, callback) { var relativeFilePath = path.resolve(file).slice(process.cwd().length + 1); + var destinationPath = (options.destination ? '/' + options.destination : '') + '/' + relativeFilePath; + console.log('Uploading file %s -> %s', relativeFilePath.cyan, destinationPath.cyan); - console.log('Uploading file %s -> %s', relativeFilePath.cyan, ((options.destination ? options.destination : '') + '/' + relativeFilePath).cyan); + superagent.put(config.server() + API + relativeFilePath).query(gQuery).attach('file', file).end(function (error, result) { + if (error) return callback(error); + if (result.statusCode !== 201) return callback(new Error('Error uploading file: ' + result.statusCode)); - superagent.put(config.server() + API + relativeFilePath).query(gQuery).attach('file', file).end(callback); + console.log('Uploaded to ' + config.server() + destinationPath); + }); }, function (error) { if (error) { console.log('Failed to put file.', error);