Skip to content

Instantly share code, notes, and snippets.

@hc2p
Last active December 14, 2015 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hc2p/5013922 to your computer and use it in GitHub Desktop.
Save hc2p/5013922 to your computer and use it in GitHub Desktop.
upload: function(file) {
var def = new $.Deferred();
var that = this;
var xhr = this.client.writeFile(file.name, file, {noOverwrite: true}, function(error, metadata) {
if (error) {
def.reject(error);
return;
}
def.resolve(metadata);
}, this.onUploadProgress);
return def.promise();
},
getSharedUrl: function(metadata) {
var def = new $.Deferred();
var that = this;
this.client.makeUrl(metadata.path, function(error, metadata) {
if (error) {
def.reject(error);
return;
}
def.resolve(metadata);
}, this.onSharedUrlProgress);
return def.promise();
}
$.when(this.upload(file)).
pipe(this.getSharedUrl).
done(...).
fail(...);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment