forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular-file-upload-tests.ts
47 lines (40 loc) · 1.34 KB
/
angular-file-upload-tests.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/// <reference path="angular-file-upload.d.ts" />
module controllers {
"use strict";
var controllerId = "upload";
class Upload {
static $inject = ["$upload"];
constructor(
private $upload: ng.angularFileUpload.IUploadService
) {
}
onFileSelect($files: File[]) {
//$files: an array of files selected, each file has name, size, and type.
var uploads: ng.IPromise<any>[] = [];
for (var i = 0; i < $files.length; i++) {
var file = $files[i];
uploads.push(this.$upload.upload<any>({
url: "/api/upload",
method: "POST",
data: {
extraData: {
fileName: file.name, test: "anything"
}
},
file: file
})
.progress((evt: any) => {
console.log('progress');
})
.then(success => {
// file is uploaded successfully
console.log(success.data);
})
.catch(err => {
console.error(err);
}));
}
}
}
angular.module("app").controller(controllerId, Upload);
}