概要: - アップロードを開始する
- は
data.submit()
を呼び出す前に、'add'
セクションで火花-MD5のコードを追加します。
- あなたはファイルサイズのチェックのような他のものなど
私のスタックも行うことができます。私のNode.jsの中
コンソールログの結果:私の<script>
タグの前に
uploading adobe_flash_setup_0906278883.exe 4522ae4ce9ee143b5b18dfa4a51b01b6
file name: adobe_flash_setup_0906278883.exe (1,518,959 bytes)
read chunk number 1 of 1
finished loading :)
computed hash: 3f38a0468b52a38c34385201de4746b0
placeholder call for data.submit();
:私の<script>
タグに
<script src="https://unpkg.com/[email protected]/dist/jquery.min.js"></script>
<script src="https://unpkg.com/[email protected]/js/vendor/jquery.ui.widget.js"></script>
<script src="https://unpkg.com/[email protected]/js/jquery.iframe-transport.js"></script>
<script src="https://unpkg.com/[email protected]/js/jquery.fileupload.js"></script>
<script src="https://unpkg.com/[email protected]/spark-md5.min.js"></script>
:
$('#fileupload').fileupload({
url: 'https://mywebsite/blahblahblahblahblah',
paramName: '_file',
dataType: 'json',
type: 'POST',
autoUpload: true,
add: function(e, data) {
console.log('uploading', data.files[0].name, _hashID);
var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
file = data.files[0],
chunkSize = 2097152, // read in chunks of 2MB
chunks = Math.ceil(file.size/chunkSize),
currentChunk = 0,
spark = new SparkMD5.ArrayBuffer(),
frOnload = function(e) {
console.log("\nread chunk number " + parseInt(currentChunk + 1) + " of " + chunks);
spark.append(e.target.result); // append array buffer
currentChunk++;
if (currentChunk < chunks)
loadNext();
else
console.log("\nfinished loading :)\n\ncomputed hash:\n" + spark.end());
console.log("placeholder call for data.submit();")
data.submit();
},
frOnerror = function() {
console.log("\noops, something went wrong.");
};
function loadNext() {
var fileReader = new FileReader();
fileReader.onload = frOnload;
fileReader.onerror = frOnerror;
var start = currentChunk * chunkSize,
end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
};
console.log("file name: " + file.name + " (" + file.size.toString().replace(/\B(?=(?:\d{3})+(?!\d))/g, ',') + " bytes)\n");
loadNext();
},
progress: function (e, data) {
// usual stuff
},
done: function (e, data) {
// usual stuff
}