|
@@ -134,325 +134,326 @@ export default { |
|
|
// }, 1000); |
|
|
// }, 1000); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
computeMD5(file) { |
|
|
|
|
|
this.resetStatus(); |
|
|
|
|
|
const blobSlice = |
|
|
|
|
|
File.prototype.slice || |
|
|
|
|
|
File.prototype.mozSlice || |
|
|
|
|
|
File.prototype.webkitSlice, |
|
|
|
|
|
chunkSize = 1024 * 1024 * 64, |
|
|
|
|
|
chunks = Math.ceil(file.size / chunkSize), |
|
|
|
|
|
spark = new SparkMD5.ArrayBuffer(), |
|
|
|
|
|
fileReader = new FileReader(); |
|
|
|
|
|
let currentChunk = 0; |
|
|
|
|
|
|
|
|
|
|
|
const time = new Date().getTime(); |
|
|
|
|
|
// console.log('计算MD5...') |
|
|
|
|
|
this.status = this.dropzoneParams.data('md5-computing'); |
|
|
|
|
|
file.totalChunkCounts = chunks; |
|
|
|
|
|
loadNext(); |
|
|
|
|
|
|
|
|
|
|
|
fileReader.onload = (e) => { |
|
|
|
|
|
fileLoaded.call(this, e); |
|
|
|
|
|
}; |
|
|
|
|
|
fileReader.onerror = (err) => { |
|
|
|
|
|
console.warn('oops, something went wrong.', err); |
|
|
|
|
|
file.cancel(); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
function fileLoaded(e) { |
|
|
|
|
|
spark.append(e.target.result); // Append array buffer |
|
|
|
|
|
currentChunk++; |
|
|
|
|
|
if (currentChunk < chunks) { |
|
|
|
|
|
// console.log(`第${currentChunk}分片解析完成, 开始第${currentChunk +1}/${chunks}分片解析`); |
|
|
|
|
|
this.status = `${this.dropzoneParams.data('loading-file')} ${( |
|
|
|
|
|
(currentChunk / chunks) * |
|
|
|
|
|
100 |
|
|
|
|
|
).toFixed(2)}% (${currentChunk}/${chunks})`; |
|
|
|
|
|
this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2)); |
|
|
|
|
|
loadNext(); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const md5 = spark.end(); |
|
|
|
|
|
console.log( |
|
|
|
|
|
`MD5计算完成:${file.name} \nMD5:${md5} \n分片:${chunks} 大小:${ |
|
|
|
|
|
file.size |
|
|
|
|
|
} 用时:${(new Date().getTime() - time) / 1000} s` |
|
|
|
|
|
); |
|
|
|
|
|
spark.destroy(); // 释放缓存 |
|
|
|
|
|
file.uniqueIdentifier = md5; // 将文件md5赋值给文件唯一标识 |
|
|
|
|
|
file.cmd5 = false; // 取消计算md5状态 |
|
|
|
|
|
this.computeMD5Success(file); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function loadNext() { |
|
|
|
|
|
const start = currentChunk * chunkSize; |
|
|
|
|
|
const end = |
|
|
|
|
|
start + chunkSize >= file.size ? file.size : start + chunkSize; |
|
|
|
|
|
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async computeMD5Success(md5edFile) { |
|
|
|
|
|
const file = await this.getSuccessChunks(md5edFile); |
|
|
|
|
|
try { |
|
|
|
|
|
if (file.uploadID == '' || file.uuid == '') { |
|
|
|
|
|
// 未上传过 |
|
|
|
|
|
await this.newMultiUpload(file); |
|
|
|
|
|
if (file.uploadID != '' && file.uuid != '') { |
|
|
|
|
|
file.chunks = ''; |
|
|
|
|
|
this.multipartUpload(file); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 失败如何处理 |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (file.uploaded == '1') { |
|
|
|
|
|
// 已上传成功 |
|
|
|
|
|
// 秒传 |
|
|
|
|
|
if (file.attachID == '0') { |
|
|
|
|
|
// 删除数据集记录,未删除文件 |
|
|
|
|
|
await addAttachment(file); |
|
|
|
|
|
} |
|
|
|
|
|
//不同数据集上传同一个文件 |
|
|
|
|
|
if (file.datasetID != '') { |
|
|
|
|
|
if (Number(file.datasetID) != file.datasetId) { |
|
|
|
|
|
var info = "该文件已上传,对应数据集(" + file.datasetName + ")-文件(" + file.realName + ")"; |
|
|
|
|
|
window.alert(info); |
|
|
|
|
|
window.location.reload(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
console.log('文件已上传完成'); |
|
|
|
|
|
this.progress = 100; |
|
|
|
|
|
this.status = this.dropzoneParams.data('upload-complete'); |
|
|
|
|
|
this.finishUpload(file); |
|
|
|
|
|
} else { |
|
|
|
|
|
// 断点续传 |
|
|
|
|
|
this.multipartUpload(file); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
this.emitDropzoneFailed(file); |
|
|
|
|
|
console.log(error); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function addAttachment(file) { |
|
|
|
|
|
return await axios.post( |
|
|
|
|
|
'/attachments/add', |
|
|
|
|
|
qs.stringify({ |
|
|
|
|
|
uuid: file.uuid, |
|
|
|
|
|
file_name: file.name, |
|
|
|
|
|
size: file.size, |
|
|
|
|
|
dataset_id: file.datasetId, |
|
|
|
|
|
_csrf: csrf |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async getSuccessChunks(file) { |
|
|
|
|
|
const params = { |
|
|
|
|
|
params: { |
|
|
|
|
|
md5: file.uniqueIdentifier, |
|
|
|
|
|
type: cloud_brain_type, |
|
|
|
|
|
_csrf: csrf |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
try { |
|
|
|
|
|
const response = await axios.get('/attachments/get_chunks', params); |
|
|
|
|
|
file.uploadID = response.data.uploadID; |
|
|
|
|
|
file.uuid = response.data.uuid; |
|
|
|
|
|
file.uploaded = response.data.uploaded; |
|
|
|
|
|
file.chunks = response.data.chunks; |
|
|
|
|
|
file.attachID = response.data.attachID; |
|
|
|
|
|
file.datasetID = response.data.datasetID; |
|
|
|
|
|
file.datasetName = response.data.datasetName; |
|
|
|
|
|
file.realName = response.data.fileName; |
|
|
|
|
|
return file; |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
this.emitDropzoneFailed(file); |
|
|
|
|
|
console.log('getSuccessChunks catch: ', error); |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
async newMultiUpload(file) { |
|
|
|
|
|
const res = await axios.get('/attachments/new_multipart', { |
|
|
|
|
|
params: { |
|
|
|
|
|
totalChunkCounts: file.totalChunkCounts, |
|
|
|
|
|
md5: file.uniqueIdentifier, |
|
|
|
|
|
size: file.size, |
|
|
|
|
|
fileType: file.type, |
|
|
|
|
|
type: cloud_brain_type, |
|
|
|
|
|
_csrf: csrf |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
file.uploadID = res.data.uploadID; |
|
|
|
|
|
file.uuid = res.data.uuid; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
multipartUpload(file) { |
|
|
|
|
|
const blobSlice = |
|
|
|
|
|
File.prototype.slice || |
|
|
|
|
|
File.prototype.mozSlice || |
|
|
|
|
|
File.prototype.webkitSlice, |
|
|
|
|
|
chunkSize = 1024 * 1024 * 64, |
|
|
|
|
|
chunks = Math.ceil(file.size / chunkSize), |
|
|
|
|
|
fileReader = new FileReader(), |
|
|
|
|
|
time = new Date().getTime(); |
|
|
|
|
|
let currentChunk = 0; |
|
|
|
|
|
|
|
|
|
|
|
function loadNext() { |
|
|
|
|
|
const start = currentChunk * chunkSize; |
|
|
|
|
|
const end = |
|
|
|
|
|
start + chunkSize >= file.size ? file.size : start + chunkSize; |
|
|
|
|
|
fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function checkSuccessChunks() { |
|
|
|
|
|
const index = successChunks.indexOf((currentChunk + 1).toString()); |
|
|
|
|
|
if (index == -1) { |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function getUploadChunkUrl(currentChunk, partSize) { |
|
|
|
|
|
const res = await axios.get('/attachments/get_multipart_url', { |
|
|
|
|
|
params: { |
|
|
|
|
|
uuid: file.uuid, |
|
|
|
|
|
uploadID: file.uploadID, |
|
|
|
|
|
size: partSize, |
|
|
|
|
|
chunkNumber: currentChunk + 1, |
|
|
|
|
|
type: cloud_brain_type, |
|
|
|
|
|
_csrf: csrf |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
urls[currentChunk] = res.data.url; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function uploadMinio(url, e) { |
|
|
|
|
|
const res = await axios.put(url, e.target.result); |
|
|
|
|
|
etags[currentChunk] = res.headers.etag; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function updateChunk(currentChunk) { |
|
|
|
|
|
await axios.post( |
|
|
|
|
|
'/attachments/update_chunk', |
|
|
|
|
|
qs.stringify({ |
|
|
|
|
|
uuid: file.uuid, |
|
|
|
|
|
chunkNumber: currentChunk + 1, |
|
|
|
|
|
etag: etags[currentChunk], |
|
|
|
|
|
_csrf: csrf |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function uploadPart(currentChunk, partSize, e) { |
|
|
|
|
|
console.log(e); |
|
|
|
|
|
let params = new FormData(); |
|
|
|
|
|
params.append("uuid", file.uuid); |
|
|
|
|
|
params.append("uploadId", file.uploadID); |
|
|
|
|
|
params.append("size", partSize); |
|
|
|
|
|
params.append("chunkNumber", currentChunk + 1); |
|
|
|
|
|
params.append("file", e.target.file); |
|
|
|
|
|
params.append("_csrf", csrf); |
|
|
|
|
|
return await axios.post('/attachments/upload_part', |
|
|
|
|
|
params, |
|
|
|
|
|
{headers: {'Content-Type': 'multipart/form-data'}} |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function uploadChunk(e) { |
|
|
|
|
|
try { |
|
|
|
|
|
if (!checkSuccessChunks()) { |
|
|
|
|
|
const start = currentChunk * chunkSize; |
|
|
|
|
|
const partSize = |
|
|
|
|
|
start + chunkSize >= file.size ? file.size - start : chunkSize; |
|
|
|
|
|
await uploadPart(currentChunk, partSize, e); |
|
|
|
|
|
|
|
|
|
|
|
// 获取分片上传url |
|
|
|
|
|
// await getUploadChunkUrl(currentChunk, partSize); |
|
|
|
|
|
// if (urls[currentChunk] != '') { |
|
|
|
|
|
// // 上传到minio |
|
|
|
|
|
// await uploadMinio(urls[currentChunk], e); |
|
|
|
|
|
// if (etags[currentChunk] != '') { |
|
|
|
|
|
// // 更新数据库:分片上传结果 |
|
|
|
|
|
// //await updateChunk(currentChunk); |
|
|
|
|
|
// } else { |
|
|
|
|
|
// console.log("上传到minio uploadChunk etags[currentChunk] == ''");// TODO |
|
|
|
|
|
// } |
|
|
|
|
|
// } else { |
|
|
|
|
|
// console.log("uploadChunk urls[currentChunk] != ''");// TODO |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.log(error); |
|
|
|
|
|
this.emitDropzoneFailed(file); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async function completeUpload() { |
|
|
|
|
|
return await axios.post( |
|
|
|
|
|
'/attachments/complete_multipart', |
|
|
|
|
|
qs.stringify({ |
|
|
|
|
|
uuid: file.uuid, |
|
|
|
|
|
uploadID: file.uploadID, |
|
|
|
|
|
file_name: file.name, |
|
|
|
|
|
size: file.size, |
|
|
|
|
|
dataset_id: file.datasetId, |
|
|
|
|
|
type: cloud_brain_type, |
|
|
|
|
|
_csrf: csrf |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const successChunks = []; |
|
|
|
|
|
let successParts = []; |
|
|
|
|
|
successParts = file.chunks.split(','); |
|
|
|
|
|
for (let i = 0; i < successParts.length; i++) { |
|
|
|
|
|
successChunks[i] = successParts[i].split('-')[0]; |
|
|
|
|
|
} |
|
|
|
|
|
const urls = []; // TODO const ? |
|
|
|
|
|
const etags = []; |
|
|
|
|
|
console.log('上传分片...'); |
|
|
|
|
|
this.status = this.dropzoneParams.data('uploading'); |
|
|
|
|
|
loadNext(); |
|
|
|
|
|
fileReader.onload = async (e) => { |
|
|
|
|
|
await uploadChunk(e); |
|
|
|
|
|
fileReader.abort(); |
|
|
|
|
|
currentChunk++; |
|
|
|
|
|
if (currentChunk < chunks) { |
|
|
|
|
|
console.log( |
|
|
|
|
|
`第${currentChunk}个分片上传完成, 开始第${currentChunk + |
|
|
|
|
|
1}/${chunks}个分片上传` |
|
|
|
|
|
); |
|
|
|
|
|
this.progress = Math.ceil((currentChunk / chunks) * 100); |
|
|
|
|
|
this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2)); |
|
|
|
|
|
this.status = `${this.dropzoneParams.data('uploading')} ${( |
|
|
|
|
|
(currentChunk / chunks) * |
|
|
|
|
|
100 |
|
|
|
|
|
).toFixed(2)}%`; |
|
|
|
|
|
await loadNext(); |
|
|
|
|
|
} else { |
|
|
|
|
|
await completeUpload(); |
|
|
|
|
|
console.log( |
|
|
|
|
|
`文件上传完成:${file.name} \n分片:${chunks} 大小:${ |
|
|
|
|
|
file.size |
|
|
|
|
|
} 用时:${(new Date().getTime() - time) / 1000} s` |
|
|
|
|
|
); |
|
|
|
|
|
this.progress = 100; |
|
|
|
|
|
this.status = this.dropzoneParams.data('upload-complete'); |
|
|
|
|
|
this.finishUpload(file); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
</script> |
|
|
|
|
|
|
|
|
// computeMD5(file) { |
|
|
|
|
|
// this.resetStatus(); |
|
|
|
|
|
// const blobSlice = |
|
|
|
|
|
// File.prototype.slice || |
|
|
|
|
|
// File.prototype.mozSlice || |
|
|
|
|
|
// File.prototype.webkitSlice, |
|
|
|
|
|
// chunkSize = 1024 * 1024 * 64, |
|
|
|
|
|
// chunks = Math.ceil(file.size / chunkSize), |
|
|
|
|
|
// spark = new SparkMD5.ArrayBuffer(), |
|
|
|
|
|
// fileReader = new FileReader(); |
|
|
|
|
|
// let currentChunk = 0; |
|
|
|
|
|
|
|
|
|
|
|
// const time = new Date().getTime(); |
|
|
|
|
|
// // console.log('计算MD5...') |
|
|
|
|
|
// this.status = this.dropzoneParams.data('md5-computing'); |
|
|
|
|
|
// file.totalChunkCounts = chunks; |
|
|
|
|
|
// loadNext(); |
|
|
|
|
|
|
|
|
|
|
|
// fileReader.onload = (e) => { |
|
|
|
|
|
// fileLoaded.call(this, e); |
|
|
|
|
|
// }; |
|
|
|
|
|
// fileReader.onerror = (err) => { |
|
|
|
|
|
// console.warn('oops, something went wrong.', err); |
|
|
|
|
|
// file.cancel(); |
|
|
|
|
|
// }; |
|
|
|
|
|
|
|
|
|
|
|
// function fileLoaded(e) { |
|
|
|
|
|
// spark.append(e.target.result); // Append array buffer |
|
|
|
|
|
// currentChunk++; |
|
|
|
|
|
// if (currentChunk < chunks) { |
|
|
|
|
|
// // console.log(`第${currentChunk}分片解析完成, 开始第${currentChunk +1}/${chunks}分片解析`); |
|
|
|
|
|
// this.status = `${this.dropzoneParams.data('loading-file')} ${( |
|
|
|
|
|
// (currentChunk / chunks) * |
|
|
|
|
|
// 100 |
|
|
|
|
|
// ).toFixed(2)}% (${currentChunk}/${chunks})`; |
|
|
|
|
|
// this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2)); |
|
|
|
|
|
// loadNext(); |
|
|
|
|
|
// return; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// const md5 = spark.end(); |
|
|
|
|
|
// console.log( |
|
|
|
|
|
// `MD5计算完成:${file.name} \nMD5:${md5} \n分片:${chunks} 大小:${ |
|
|
|
|
|
// file.size |
|
|
|
|
|
// } 用时:${(new Date().getTime() - time) / 1000} s` |
|
|
|
|
|
// ); |
|
|
|
|
|
// spark.destroy(); // 释放缓存 |
|
|
|
|
|
// file.uniqueIdentifier = md5; // 将文件md5赋值给文件唯一标识 |
|
|
|
|
|
// file.cmd5 = false; // 取消计算md5状态 |
|
|
|
|
|
// this.computeMD5Success(file); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// function loadNext() { |
|
|
|
|
|
// const start = currentChunk * chunkSize; |
|
|
|
|
|
// const end = |
|
|
|
|
|
// start + chunkSize >= file.size ? file.size : start + chunkSize; |
|
|
|
|
|
// fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)); |
|
|
|
|
|
// } |
|
|
|
|
|
// }, |
|
|
|
|
|
|
|
|
|
|
|
// async computeMD5Success(md5edFile) { |
|
|
|
|
|
// const file = await this.getSuccessChunks(md5edFile); |
|
|
|
|
|
// try { |
|
|
|
|
|
// if (file.uploadID == '' || file.uuid == '') { |
|
|
|
|
|
// // 未上传过 |
|
|
|
|
|
// await this.newMultiUpload(file); |
|
|
|
|
|
// if (file.uploadID != '' && file.uuid != '') { |
|
|
|
|
|
// file.chunks = ''; |
|
|
|
|
|
// this.multipartUpload(file); |
|
|
|
|
|
// } else { |
|
|
|
|
|
// // 失败如何处理 |
|
|
|
|
|
// return; |
|
|
|
|
|
// } |
|
|
|
|
|
// return; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// if (file.uploaded == '1') { |
|
|
|
|
|
// // 已上传成功 |
|
|
|
|
|
// // 秒传 |
|
|
|
|
|
// if (file.attachID == '0') { |
|
|
|
|
|
// // 删除数据集记录,未删除文件 |
|
|
|
|
|
// await addAttachment(file); |
|
|
|
|
|
// } |
|
|
|
|
|
// //不同数据集上传同一个文件 |
|
|
|
|
|
// if (file.datasetID != '') { |
|
|
|
|
|
// if (Number(file.datasetID) != file.datasetId) { |
|
|
|
|
|
// var info = "该文件已上传,对应数据集(" + file.datasetName + ")-文件(" + file.realName + ")"; |
|
|
|
|
|
// window.alert(info); |
|
|
|
|
|
// window.location.reload(); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// console.log('文件已上传完成'); |
|
|
|
|
|
// this.progress = 100; |
|
|
|
|
|
// this.status = this.dropzoneParams.data('upload-complete'); |
|
|
|
|
|
// this.finishUpload(file); |
|
|
|
|
|
// } else { |
|
|
|
|
|
// // 断点续传 |
|
|
|
|
|
// this.multipartUpload(file); |
|
|
|
|
|
// } |
|
|
|
|
|
// } catch (error) { |
|
|
|
|
|
// this.emitDropzoneFailed(file); |
|
|
|
|
|
// console.log(error); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// async function addAttachment(file) { |
|
|
|
|
|
// return await axios.post( |
|
|
|
|
|
// '/attachments/add', |
|
|
|
|
|
// qs.stringify({ |
|
|
|
|
|
// uuid: file.uuid, |
|
|
|
|
|
// file_name: file.name, |
|
|
|
|
|
// size: file.size, |
|
|
|
|
|
// dataset_id: file.datasetId, |
|
|
|
|
|
// _csrf: csrf |
|
|
|
|
|
// }) |
|
|
|
|
|
// ); |
|
|
|
|
|
// } |
|
|
|
|
|
// }, |
|
|
|
|
|
|
|
|
|
|
|
// async getSuccessChunks(file) { |
|
|
|
|
|
// const params = { |
|
|
|
|
|
// params: { |
|
|
|
|
|
// md5: file.uniqueIdentifier, |
|
|
|
|
|
// type: cloud_brain_type, |
|
|
|
|
|
// _csrf: csrf |
|
|
|
|
|
// } |
|
|
|
|
|
// }; |
|
|
|
|
|
// try { |
|
|
|
|
|
// const response = await axios.get('/attachments/get_chunks', params); |
|
|
|
|
|
// file.uploadID = response.data.uploadID; |
|
|
|
|
|
// file.uuid = response.data.uuid; |
|
|
|
|
|
// file.uploaded = response.data.uploaded; |
|
|
|
|
|
// file.chunks = response.data.chunks; |
|
|
|
|
|
// file.attachID = response.data.attachID; |
|
|
|
|
|
// file.datasetID = response.data.datasetID; |
|
|
|
|
|
// file.datasetName = response.data.datasetName; |
|
|
|
|
|
// file.realName = response.data.fileName; |
|
|
|
|
|
// return file; |
|
|
|
|
|
// } catch (error) { |
|
|
|
|
|
// this.emitDropzoneFailed(file); |
|
|
|
|
|
// console.log('getSuccessChunks catch: ', error); |
|
|
|
|
|
// return null; |
|
|
|
|
|
// } |
|
|
|
|
|
// }, |
|
|
|
|
|
|
|
|
|
|
|
// async newMultiUpload(file) { |
|
|
|
|
|
// const res = await axios.get('/attachments/new_multipart', { |
|
|
|
|
|
// params: { |
|
|
|
|
|
// totalChunkCounts: file.totalChunkCounts, |
|
|
|
|
|
// md5: file.uniqueIdentifier, |
|
|
|
|
|
// size: file.size, |
|
|
|
|
|
// fileType: file.type, |
|
|
|
|
|
// type: cloud_brain_type, |
|
|
|
|
|
// _csrf: csrf |
|
|
|
|
|
// } |
|
|
|
|
|
// }); |
|
|
|
|
|
// console.log("dsnjs", res) |
|
|
|
|
|
// file.uploadID = res.data.uploadID; |
|
|
|
|
|
// file.uuid = res.data.uuid; |
|
|
|
|
|
// }, |
|
|
|
|
|
|
|
|
|
|
|
// multipartUpload(file) { |
|
|
|
|
|
// const blobSlice = |
|
|
|
|
|
// File.prototype.slice || |
|
|
|
|
|
// File.prototype.mozSlice || |
|
|
|
|
|
// File.prototype.webkitSlice, |
|
|
|
|
|
// chunkSize = 1024 * 1024 * 64, |
|
|
|
|
|
// chunks = Math.ceil(file.size / chunkSize), |
|
|
|
|
|
// fileReader = new FileReader(), |
|
|
|
|
|
// time = new Date().getTime(); |
|
|
|
|
|
// let currentChunk = 0; |
|
|
|
|
|
|
|
|
|
|
|
// function loadNext() { |
|
|
|
|
|
// const start = currentChunk * chunkSize; |
|
|
|
|
|
// const end = |
|
|
|
|
|
// start + chunkSize >= file.size ? file.size : start + chunkSize; |
|
|
|
|
|
// fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// function checkSuccessChunks() { |
|
|
|
|
|
// const index = successChunks.indexOf((currentChunk + 1).toString()); |
|
|
|
|
|
// if (index == -1) { |
|
|
|
|
|
// return false; |
|
|
|
|
|
// } |
|
|
|
|
|
// return true; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// // async function getUploadChunkUrl(currentChunk, partSize) { |
|
|
|
|
|
// // const res = await axios.get('/attachments/get_multipart_url', { |
|
|
|
|
|
// // params: { |
|
|
|
|
|
// // uuid: file.uuid, |
|
|
|
|
|
// // uploadID: file.uploadID, |
|
|
|
|
|
// // size: partSize, |
|
|
|
|
|
// // chunkNumber: currentChunk + 1, |
|
|
|
|
|
// // type: cloud_brain_type, |
|
|
|
|
|
// // _csrf: csrf |
|
|
|
|
|
// // } |
|
|
|
|
|
// // }); |
|
|
|
|
|
// // urls[currentChunk] = res.data.url; |
|
|
|
|
|
// // } |
|
|
|
|
|
|
|
|
|
|
|
// // async function uploadMinio(url, e) { |
|
|
|
|
|
// // const res = await axios.put(url, e.target.result); |
|
|
|
|
|
// // etags[currentChunk] = res.headers.etag; |
|
|
|
|
|
// // } |
|
|
|
|
|
|
|
|
|
|
|
// // async function updateChunk(currentChunk) { |
|
|
|
|
|
// // await axios.post( |
|
|
|
|
|
// // '/attachments/update_chunk', |
|
|
|
|
|
// // qs.stringify({ |
|
|
|
|
|
// // uuid: file.uuid, |
|
|
|
|
|
// // chunkNumber: currentChunk + 1, |
|
|
|
|
|
// // etag: etags[currentChunk], |
|
|
|
|
|
// // _csrf: csrf |
|
|
|
|
|
// // }) |
|
|
|
|
|
// // ); |
|
|
|
|
|
// // } |
|
|
|
|
|
|
|
|
|
|
|
// async function uploadPart(currentChunk, partSize, e) { |
|
|
|
|
|
// console.log(e); |
|
|
|
|
|
// let params = new FormData(); |
|
|
|
|
|
// params.append("uuid", file.uuid); |
|
|
|
|
|
// params.append("uploadId", file.uploadID); |
|
|
|
|
|
// params.append("size", partSize); |
|
|
|
|
|
// params.append("chunkNumber", currentChunk + 1); |
|
|
|
|
|
// params.append("file", e.target.file); |
|
|
|
|
|
// params.append("_csrf", csrf); |
|
|
|
|
|
// return await axios.post('/attachments/upload_part', |
|
|
|
|
|
// params, |
|
|
|
|
|
// {headers: {'Content-Type': 'multipart/form-data'}} |
|
|
|
|
|
// ); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// async function uploadChunk(e) { |
|
|
|
|
|
// try { |
|
|
|
|
|
// if (!checkSuccessChunks()) { |
|
|
|
|
|
// const start = currentChunk * chunkSize; |
|
|
|
|
|
// const partSize = |
|
|
|
|
|
// start + chunkSize >= file.size ? file.size - start : chunkSize; |
|
|
|
|
|
// await uploadPart(currentChunk, partSize, e); |
|
|
|
|
|
|
|
|
|
|
|
// // 获取分片上传url |
|
|
|
|
|
// // await getUploadChunkUrl(currentChunk, partSize); |
|
|
|
|
|
// // if (urls[currentChunk] != '') { |
|
|
|
|
|
// // // 上传到minio |
|
|
|
|
|
// // await uploadMinio(urls[currentChunk], e); |
|
|
|
|
|
// // if (etags[currentChunk] != '') { |
|
|
|
|
|
// // // 更新数据库:分片上传结果 |
|
|
|
|
|
// // //await updateChunk(currentChunk); |
|
|
|
|
|
// // } else { |
|
|
|
|
|
// // console.log("上传到minio uploadChunk etags[currentChunk] == ''");// TODO |
|
|
|
|
|
// // } |
|
|
|
|
|
// // } else { |
|
|
|
|
|
// // console.log("uploadChunk urls[currentChunk] != ''");// TODO |
|
|
|
|
|
// // } |
|
|
|
|
|
|
|
|
|
|
|
// } |
|
|
|
|
|
// } catch (error) { |
|
|
|
|
|
// console.log(error); |
|
|
|
|
|
// this.emitDropzoneFailed(file); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// async function completeUpload() { |
|
|
|
|
|
// return await axios.post( |
|
|
|
|
|
// '/attachments/complete_multipart', |
|
|
|
|
|
// qs.stringify({ |
|
|
|
|
|
// uuid: file.uuid, |
|
|
|
|
|
// uploadID: file.uploadID, |
|
|
|
|
|
// file_name: file.name, |
|
|
|
|
|
// size: file.size, |
|
|
|
|
|
// dataset_id: file.datasetId, |
|
|
|
|
|
// type: cloud_brain_type, |
|
|
|
|
|
// _csrf: csrf |
|
|
|
|
|
// }) |
|
|
|
|
|
// ); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// const successChunks = []; |
|
|
|
|
|
// let successParts = []; |
|
|
|
|
|
// successParts = file.chunks.split(','); |
|
|
|
|
|
// for (let i = 0; i < successParts.length; i++) { |
|
|
|
|
|
// successChunks[i] = successParts[i].split('-')[0]; |
|
|
|
|
|
// } |
|
|
|
|
|
// const urls = []; // TODO const ? |
|
|
|
|
|
// const etags = []; |
|
|
|
|
|
// console.log('上传分片...'); |
|
|
|
|
|
// this.status = this.dropzoneParams.data('uploading'); |
|
|
|
|
|
// loadNext(); |
|
|
|
|
|
// fileReader.onload = async (e) => { |
|
|
|
|
|
// await uploadChunk(e); |
|
|
|
|
|
// fileReader.abort(); |
|
|
|
|
|
// currentChunk++; |
|
|
|
|
|
// if (currentChunk < chunks) { |
|
|
|
|
|
// console.log( |
|
|
|
|
|
// `第${currentChunk}个分片上传完成, 开始第${currentChunk + |
|
|
|
|
|
// 1}/${chunks}个分片上传` |
|
|
|
|
|
// ); |
|
|
|
|
|
// this.progress = Math.ceil((currentChunk / chunks) * 100); |
|
|
|
|
|
// this.updateProgress(file, ((currentChunk / chunks) * 100).toFixed(2)); |
|
|
|
|
|
// this.status = `${this.dropzoneParams.data('uploading')} ${( |
|
|
|
|
|
// (currentChunk / chunks) * |
|
|
|
|
|
// 100 |
|
|
|
|
|
// ).toFixed(2)}%`; |
|
|
|
|
|
// await loadNext(); |
|
|
|
|
|
// } else { |
|
|
|
|
|
// await completeUpload(); |
|
|
|
|
|
// console.log( |
|
|
|
|
|
// `文件上传完成:${file.name} \n分片:${chunks} 大小:${ |
|
|
|
|
|
// file.size |
|
|
|
|
|
// } 用时:${(new Date().getTime() - time) / 1000} s` |
|
|
|
|
|
// ); |
|
|
|
|
|
// this.progress = 100; |
|
|
|
|
|
// this.status = this.dropzoneParams.data('upload-complete'); |
|
|
|
|
|
// this.finishUpload(file); |
|
|
|
|
|
// } |
|
|
|
|
|
// }; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// }; |
|
|
|
|
|
// </script> |
|
|
|
|
|
|
|
|
<style> |
|
|
<style> |
|
|
.dropzone-wrapper { |
|
|
.dropzone-wrapper { |
|
|