Skip to content

Instantly share code, notes, and snippets.

@iamblue
Created August 29, 2014 06:57
Show Gist options
  • Save iamblue/5f0b728670cffbc9b18c to your computer and use it in GitHub Desktop.
Save iamblue/5f0b728670cffbc9b18c to your computer and use it in GitHub Desktop.
uploader = $fileUploader.create(
scope: $scope
url: "http://#{$rootScope.api}/proposal/upload"
formData: [{
key: \value
}]
filters: [
(item) ->
if item.size >10000000
alert \size不得超過10mb
false
else
true
]
)
uploader.filters.push (item) ->
true
$scope.picPool = []
uploader.bind \progress, (event, item, progress) ->
console.info \Progress: + progress, item
uploader.bind \beforeupload, (event, item)->
console.info 'Before upload', item
uploader.bind \complete, (event, xhr, item)->
_x = angular.fromJson xhr.response
$scope.change = true
if _x.n == \error
alert \上傳圖片需為2000x1500px
else
$scope.picPool.push {u:_x.n,m:0}
$scope.oi = false
$scope.mainpic = $scope.picPool[0].u
_ym = 0
for v in $scope.picPool
if v.m == 1
_ym = 1
if _ym == 0
$scope.picPool[0].m = 1
uploader.bind \completeall, (event, items) !->
$scope.oi = false
$scope.uploader = uploader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment