-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
128 lines (109 loc) · 3.78 KB
/
index.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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>腾讯云万象优图 - 示例程序</title>
<script type="text/javascript" src="./jquery.min.js"></script>
<script type="text/javascript" src="./jquery.form.min.js"></script>
</head>
<body>
<div>
<h2>腾讯云万象优图 - 示例程序</h2>
<form id="uploadForm">
<input type="file" name="FileContent"></input>
<input id="subbtn" type="submit">
</form>
<br>
<form id="uploadBase64">
<input type="file" name="FileContent2"></input>
<input type="hidden" value="" id="file-base64"></input>
<input id="subbtn2" type="button" value="base64提交">
</form>
<div id="downloadRet" style="display:none">
<h3>下载链接</h3>
<span id="downloadUrl"></span><input id="downloadBtn" type="button" value="下载"><br/>
<img id="downloadImg" src=""></img>
<h3>文件ID</h3>
<div id="fileid"></div>
<h3>管理URL</h3>
<span id="url"></span>
<span id="imgInfo"></span>
</div>
</div>
<script type="text/javascript">
$('input[name=FileContent]').change(function () {
initUploadForm();
});
$('input[name=FileContent2]').change(function (e) {
var self = $(this);
var file = e.target.files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = function(e){
$('#file-base64').val(this.result);
}
});
$('body').on('click', '#downloadBtn', function(){
$('#downloadImg').attr('src', $('#downloadUrl').text());
return false;
});
$('body').on('click', '#subbtn2', function(){
base64Post()
return false;
});
function initUploadForm () {
// 请将以下获取签名的链接换成您部署好的服务端http url
// 建议通过业务登陆态检查来增强安全性,避免签名被非法获取
$.getJSON('http://127.0.0.1/ci/php/auth.php', function(data) {
var sign = data.sign,
url = data.url + '?sign=' + encodeURIComponent(sign);
var options = {
type: 'post',
url: url,
dataType: 'json',
success:function(ret) {
$('#downloadUrl').html(ret.data.download_url);
$('#fileid').text(ret.data.fileid);
$('#url').text(ret.data.url);
$('#downloadRet').show();
},
error:function (ret) {
alert(ret.responseText);
}
};
// pass options to ajaxForm
$('#uploadForm').ajaxForm(options);
});
}
function base64Post () {
// 请将以下获取签名的链接换成您部署好的服务端http url
// 建议通过业务登陆态检查来增强安全性,避免签名被非法获取
$.getJSON('http://127.0.0.1/ci/php/auth.php', function(data) {
var sign = data.sign,
url = data.url + '?sign=' + encodeURIComponent(sign);
var formData = new FormData();
var str = $('#file-base64').val();
formData.append('FileContent', str);
var options = {
type: 'post',
url: url,
dataType: "JSON",
data:formData,
processData: false, // 告诉jQuery不要去处理发送的数据
contentType: false, // 告诉jQuery不要去设置Content-Type请求头
success:function(ret) {
$('#downloadUrl').html(ret.data.download_url);
$('#fileid').text(ret.data.fileid);
$('#url').text(ret.data.url);
$('#downloadRet').show();
},
error:function (ret) {
alert(ret.responseText);
}
};
$.ajax(options);
});
}
</script>
</body>
</html>