Show upload/processing progress for normal file uploads.

This commit is contained in:
Simo Kinnunen
2014-04-07 16:35:46 +09:00
parent c2b4bf4a90
commit 4b155a3850
5 changed files with 147 additions and 117 deletions

View File

@@ -120,37 +120,21 @@ module.exports = function ControlServiceFactory(
}
this.uploadFile = function(files) {
// Let's fake it till we can make it
var result = new TransactionService.TransactionResult({
if (files.length !== 1) {
throw new Error('Can only upload one file')
}
var tx = TransactionService.create({
id: 'storage'
})
return {
promise:
TransactionService.punch(tx.channel)
.then(function() {
$upload.upload({
url: '/api/v1/resources'
url: '/api/v1/resources?channel=' + tx.channel
, method: 'POST'
, file: files[0]
})
.then(
function(response) {
result.settled = true
result.progress = 100
result.success = true
result.lastData = 'success'
result.data.push(result.lastData)
result.body = response.data
return result
}
, function(err) {
result.settled = true
result.progress = 100
result.success = false
result.error = result.lastData = 'fail'
result.data.push(result.lastData)
return result
}
)
}
})
return tx
}
this.install = function(options) {