Created
March 4, 2016 13:30
-
-
Save rubenCodeforges/102db11ec4c316948e56 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
@App.factory 'MediaHelper', ['mytvConfig','$q','$upload', (mytvConfig,$q,$upload)-> | |
helper = | |
settings: | |
maxFileSize: 1300 | |
uploadVideo: (files)-> | |
deferred = $q.defer() | |
files.forEach (file)=> | |
if file.size/1000000 < @settings.maxFileSize | |
data = | |
api_password: mytvConfig.wistia.id | |
project_id: mytvConfig.me.remoteProjectId | |
file: file | |
$upload.upload( | |
url: 'https://upload.wistia.com', | |
method: 'POST', | |
data: data | |
) | |
.progress (obj) -> | |
progress = Math.round( obj.loaded / obj.totalSize * 100 ) | |
deferred.notify progress | |
.success (response) -> | |
deferred.resolve response | |
else | |
deferred.reject 'File: "'+file.name+'", is too big.' | |
deferred.promise | |
helper | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment