Created
May 25, 2016 05:37
-
-
Save nothingrealhappen/91e585aedeafb6f6db4711f23ab6b150 to your computer and use it in GitHub Desktop.
qiniu-upload-demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script> | |
</head> | |
<body> | |
<textarea id="content" cols="30" rows="10"></textarea> | |
<button id="upload">上传</button> | |
<script> | |
var TOKEN = 'your upload token'; | |
var MINE = 'application/json'; | |
$('#upload').on('click', () => { | |
upload($('#content').val()); | |
}); | |
function upload(txt) { | |
console.log(txt); | |
var blob = new Blob([txt], {type: MINE}); | |
var fd = new FormData(); | |
fd.append('token', TOKEN); | |
fd.append('key', 'job_data.json'); | |
fd.append('file', new File([blob], 'job_data.json', {type: MINE})); | |
$.ajax({ | |
url: 'http://upload.qiniu.com', | |
method: 'POST', | |
data: fd, | |
processData: false, | |
contentType: false, | |
}); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment