-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
136 lines (105 loc) · 4.05 KB
/
index.js
File metadata and controls
136 lines (105 loc) · 4.05 KB
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
126
127
128
129
130
131
132
133
134
135
136
var _uploadId="";
var msggetStatus = document.getElementById("getStatus");
(function() {
let chunkCount = 0;
let chunkArray = []
var f = document.getElementById('f');
var msgid = document.getElementById("msg");
msgid.innerHTML="Starting Upload"
if (f.files.length)
getFileCount();
f.addEventListener('change', getFileCount, false);
function getFileCount(e) {
var fileCount = f.files.length;
var file = f.files[0];
var size = file.size;
processFile("test");
}
let count = 0;
function processFile(e) {
var fileCount = f.files.length;
let type = 0;
chunkCount++;
send(f.files[0], fileCount, 0,e,f.files[0].name);
setTimeout(loop, 10000);
function loop() {
for(let i = 1 ; i<fileCount ; i++){
chunkArray.push("started")
var file = f.files[i];
send(file, fileCount, i,e,file.name);
}
}
}
function send(piece,fileCount,count,uploadId,filename) {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
orgId = document.getElementById("orgId").value;
projectId = document.getElementById("projId").value;
endpoint = document.getElementById("endpoint").value;
base64UP = btoa(username+":"+password);
console.log(username)
console.log(password)
console.log(base64UP)
var offset = Intl.DateTimeFormat().resolvedOptions().timeZone;
console.log("offset",offset);
var formdata = new FormData();
var xhr1 = new XMLHttpRequest();
xhr1.open('POST', endpoint+'/'+projectId+'/'+orgId+'/stowrs/studies', true);
xhr1.setRequestHeader('Authorization', 'Basic '+base64UP );
//xhr1.setRequestHeader("Content-Type", "multipart/related;type='application/dicom'");
formdata.append('content', piece);
formdata.append('timeZone', '89qw');
//formdata.append('fileName', filename);
xhr1.onreadystatechange = () => {
if (xhr1.readyState === 4) {
console.log("completeUpload Triggered",xhr1.response)
}
};
xhr1.send(formdata);
}
})();
function getStatus(){
console.log("upload Id",_uploadId)
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var base64UP = btoa(username+":"+password);
var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://9n7zdsqchk.execute-api.us-east-2.amazonaws.com/dev/4754c00f-29c8-45fc-8548-73ae929bc103/5b5246b2-cf3f-4cb5-9713-ebb8cce82530/stowrs/studies/uploadstatus', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader('Authorization', 'Basic '+base64UP );
const json = {"uploadId":_uploadId};
xhr.send(JSON.stringify(json));
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
console.log(xhr.response);
var obj = eval("(" + xhr.response + ')');
var obj1 = eval("(" + obj.body + ')');
msggetStatus.innerHTML=obj1.status;
}
};
}
function getProjects(){
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
var base64UP = btoa(username+":"+password);
var endpoint = document.getElementById("endpoint").value;
var xhr = new XMLHttpRequest();
xhr.open('GET', endpoint+'/projects', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader('Authorization', 'Basic '+base64UP );
xhr.send();
xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
console.log(xhr.response);
var obj = eval("(" + xhr.response + ')');
// var obj1 = eval("(" + obj.body + ')');
// msggetStatus.innerHTML=obj1.status;
console.log("body",obj.body.projects[0].projectId)
console.log("body",obj.body.projects[0].organizationId)
console.log("body",obj.body.projects[0].projectName)
document.getElementById("orgId").value = obj.body.projects[0].organizationId;
document.getElementById("projId").value = obj.body.projects[0].projectId;
document.getElementById("projName").innerHTML="Project Name :"+obj.body.projects[0].projectName;
}
};
}