-
-
Save minwe/7d3bb296dc3e117a8967 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var blob = require('azure').createBlobService() | |
, fs = require('fs') | |
, Q = require('q') | |
var options = { publicAccessLevel: 'blob' } | |
// With Q | |
var fsLstat = Q.nbind(fs.lstat, fs); | |
var getContainer = Q.nbind(blob.createContainerIfNotExists, blob); | |
var streamFile = Q.nbind(blob.createBlockBlobFromStream, blob); | |
function upload(container, name, path, callback) { | |
var promise = getContainer(container, options) | |
.then(function() { | |
return fsLstat(path); | |
}) | |
.then(function(stats) { | |
return streamFile( | |
scontainer, name, fs.createReadStream(path), stats.size | |
); | |
}) | |
.then(function() { | |
return blob.getBlobUrl(container, name).url(); | |
}); | |
if (typeof(callback) != "undefined") { | |
promise.then(callback) | |
} else { | |
return promise; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var blob = require('azure').createBlobService() | |
, fs = require('fs') | |
var options = { publicAccessLevel: 'blob' } | |
function upload(container, name, path, callback) { | |
blob.createContainerIfNotExists(container, options, function(err) { | |
if (!err) { | |
fs.lstat(path, function(stats) { | |
if (!err) { | |
var stream = fs.createReadStream(path); | |
blob.createBlockBlobFromStream(container, name, stream, stats.size, function(err) { | |
if (!err) { | |
var url = blob.getBlobUrl(container, name).url(); | |
callback(null, error); | |
} else { | |
callback(err); | |
} | |
}); | |
} else { | |
callback(err); | |
} | |
}); | |
} else { | |
callback(err); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var blob = require('azure').createBlobService() | |
, fs = require('fs') | |
, Q = require('q') | |
var options = { publicAccessLevel: 'blob' } | |
// With Q | |
var fsLstat = Q.nbind(fs.lstat, fs); | |
var getContainer = Q.nbind(blob.createContainerIfNotExists, blob); | |
var streamFile = Q.nbind(blob.createBlockBlobFromStream, blob); | |
function upload(container, name, path) { | |
return getContainer(container, options) | |
.then(function() { | |
return fsLstat(path); | |
}) | |
.then(function(stats) { | |
return streamFile( | |
scontainer, name, fs.createReadStream(path), stats.size | |
); | |
}) | |
.then(function() { | |
return blob.getBlobUrl(container, name).url(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment