Skip to content

Instantly share code, notes, and snippets.

@endaaman
Created December 15, 2014 09:02
Show Gist options
  • Save endaaman/5cb7892a1a61a1d87ed9 to your computer and use it in GitHub Desktop.
Save endaaman/5cb7892a1a61a1d87ed9 to your computer and use it in GitHub Desktop.
'use strict'
angular.module modulePage
.config ($stateProvider) ->
$stateProvider
.state 'upload',
url: '/upload'
templateUrl: '/page/upload/upload.html'
controller: 'UploadCtrl'
.controller 'UploadCtrl',
($scope, $http) ->
$scope.upload = ->
if not $scope.files
return
data =
hoge: 'fuga'
formData = new FormData()
formData.append 'file', $scope.files[0]
formData.append 'data', angular.toJson data
$http.post '/api/document', formData,
headers:
'Content-type': undefined
transformRequest: null
.success (res)->
console.log res
.error (res)->
console.log res
.directive 'files', ->
restrict : 'A'
scope:
files: '='
link: (scope, element, attrs)->
element.on 'change', (event)->
scope.$apply ->
scope.files = event.target.files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment