-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
executable file
·125 lines (107 loc) · 3.68 KB
/
app.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var app = angular.module('myApp', []);
app.controller('MainCtrl', function($scope,$http) {
$scope.name = 'World';
$scope.files = [];
// $scope.uploadUrlService = "http://localhost:7001/RestUploadFile2PdfApi-1.0-SNAPSHOT/rest/v1/upload";
$scope.uploadUrlService = "http://localhost:7001/ima-pj-api-1.0/rest/v1/converterImagensParaPdf";
$scope.upload=function(){
return uploadAR($scope.uploadUrlService);
function uploadAR(url){
var _fileInput = document.getElementById('fileInput');
var file = _fileInput.files[0];
var imageType = /image.*/;
// if (file.type.match(imageType)) {
// var reader = new FileReader();
// console.log("ok");
// }
// var fileReader = new FileReader();
// var fileStream = fileReader.readAsArrayBuffer(file); // file is a File object
// Create FormData to send in the request
var formData = new FormData();
// Create Blob for the second part (application/octet-stream)
var fileBlob = new Blob(
[file],
{type: 'application/octet-stream'}
);
//Append fileStream to formData
formData.append('fileData', fileBlob);
formData.append('name', file.name);
return $http.post(url, formData, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(){
console.log("ok");
})
.error(function(){
console.log("fail");
});
// Restangular Custom POST
// return Restangular
// .one(url)
// .withHttpConfig({
// transformRequest: angular.identity,
// timeout: 0 // Avoid global setting's timeout on upload
// })
// .customPOST(formData, undefined, undefined, {
// 'Content-Type': undefined
// });
}
function uploadFileJson(file, url) {
var formElement = document.querySelector("form");
var fd = new FormData(formElement);
fd.append('file',file);
var request = new XMLHttpRequest();
request.open("POST", "http://localhost:7001/ima-pj-api-1.0/rest/v1/converterImagensParaPdf");
request.send(fd);
}
function uploadFileMP(file, url){
var fd = new FormData();
fd.append('file', file)
fd.append('name', file.name);
return $http.post(url, fd, {
transformRequest: angular.identity,
headers: {'Content-Type': undefined}
})
.success(function(){
console.log("ok");
})
.error(function(){
console.log("fail");
});
}
}
});
app.directive('ngFileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var model = $parse(attrs.ngFileModel);
var isMultiple = attrs.multiple;
var modelSetter = model.assign;
element.bind('change', function () {
var values = [];
angular.forEach(element[0].files, function (item) {
var value = {
// File Name
name: item.name,
//File Size
size: item.size,
//File URL to view
url: URL.createObjectURL(item),
// File Input Value
_file: item
};
values.push(value);
});
scope.$apply(function () {
if (isMultiple) {
modelSetter(scope, values);
} else {
modelSetter(scope, values[0]);
}
});
});
}
};
}]);