前端学习笔记

  • 使用以下方式可以解决使用 input type=“file” 上传图片不能连续上传多次的问题:
1
$(document).delegate('.upload', 'change', onchangeCallback);
  • 使用表单上传图片方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
var file = files[0];
var formData = new FormData();
var fileName = uuid() + file.name.slice(file.name.lastIndexOf('.'));
formData.append("key", fileName);
formData.append("policy", config.policy);
formData.append("OSSAccessKeyId", config.accessKeyId);
formData.append("signature", config.signature);
formData.append("success_action_status", 200);
formData.append("file", file);

var request = new XMLHttpRequest();
request.open("POST", config.uploadDomain, true);
request.onreadystatechange = function () {
if(request.readyState === 4 && request.status === 200) {
fileInput.parent().parent().find('input[name="message"]').attr('value', config.domain + "/" + fileName);
fileInput.parent().parent().parent().submit();
}
};

request.send(formData);