-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestFile.html
69 lines (59 loc) · 2.09 KB
/
testFile.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<input type="file" onChange="uploadfile(this)" id="imgInput">
<script>
function uploadfile() {
var self = this;
var src = document.getElementById('imgInput');
var file = src.files[0];
if(!file){return false;}
if (!file) return false;
var fName = '';
// var fSize = rst.base64Len;
var reader = new FileReader();
reader.onload = function (evt) {
console.log(evt.target.result)//即图片,此处可进行预览操作
let fSize = evt.target.result.length;
console.log(evt.target.result.length)
// let str = "hhh";
// for (var i = 0; i < 25000; i++) {
// str += i;
// }
// fSize = str.length;
var object = JSON.stringify({
name: fName, size: fSize, base64: evt.target.result
});
// object = JSON.stringify({id: 123})
// var fileId = UUID.v1();
var xhr = new XMLHttpRequest();
// src.attr("fileId", fileId);
xhr.addEventListener("load", function (evt) {
console.log(evt);
// self.uploadFormImageSuccess(evt, src,item,index);
}, false);
xhr.addEventListener("error", function (evt) {
console.error(evt);
// self.uploadFormImageError(evt, src);
}, false);
var fd = new FormData();
fd.append('upload', file);
fd.append('obj1', object);
fd.append('fileName', fName);
fd.append('type', 'uploadFileToOss');
fd.append('module', 'newMediaImage');
// fd.append('sessionId', Cache.nodeSession.id);
fd.append('sessionId', 'sessionId');
xhr.open("POST", "http://127.0.0.1:3000");
// xhr.setRequestHeader("content-type", "application/json")
xhr.send(fd);
}
reader.readAsDataURL(file);
}
</script>
</body>
</html>