Fix upload.html: camelCase multipart params, filename field, ETag/partNumber, s3Key/assetId tracking
This commit is contained in:
parent
31ca999075
commit
1862082ba7
1 changed files with 25 additions and 12 deletions
|
|
@ -622,6 +622,8 @@
|
||||||
status: 'waiting',
|
status: 'waiting',
|
||||||
progress: 0,
|
progress: 0,
|
||||||
uploadId: null,
|
uploadId: null,
|
||||||
|
s3Key: null,
|
||||||
|
assetId: null,
|
||||||
uploadedBytes: 0,
|
uploadedBytes: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -747,8 +749,9 @@
|
||||||
async function simpleUploadFile(item) {
|
async function simpleUploadFile(item) {
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', item.file);
|
formData.append('file', item.file);
|
||||||
formData.append('project_id', uploadState.selectedProject);
|
formData.append('filename', item.file.name);
|
||||||
formData.append('bin_id', uploadState.selectedBin);
|
formData.append('projectId', uploadState.selectedProject);
|
||||||
|
formData.append('binId', uploadState.selectedBin);
|
||||||
|
|
||||||
const result = await simpleUpload(formData);
|
const result = await simpleUpload(formData);
|
||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
|
|
@ -766,16 +769,20 @@
|
||||||
// Initialize upload
|
// Initialize upload
|
||||||
const initResult = await initUpload({
|
const initResult = await initUpload({
|
||||||
filename: fileName,
|
filename: fileName,
|
||||||
content_type: file.type,
|
fileSize: file.size,
|
||||||
project_id: uploadState.selectedProject,
|
contentType: file.type,
|
||||||
bin_id: uploadState.selectedBin,
|
projectId: uploadState.selectedProject,
|
||||||
|
binId: uploadState.selectedBin,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!initResult.success) {
|
if (!initResult.success) {
|
||||||
throw new Error('Failed to initialize upload');
|
throw new Error('Failed to initialize upload');
|
||||||
}
|
}
|
||||||
|
|
||||||
item.uploadId = initResult.data.upload_id;
|
const { uploadId, key, assetId } = initResult.data;
|
||||||
|
item.uploadId = uploadId;
|
||||||
|
item.s3Key = key;
|
||||||
|
item.assetId = assetId;
|
||||||
const parts = [];
|
const parts = [];
|
||||||
const totalChunks = Math.ceil(file.size / chunkSize);
|
const totalChunks = Math.ceil(file.size / chunkSize);
|
||||||
|
|
||||||
|
|
@ -787,9 +794,9 @@
|
||||||
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', chunk);
|
formData.append('file', chunk);
|
||||||
formData.append('uploadId', item.uploadId);
|
formData.append('uploadId', uploadId);
|
||||||
formData.append('partNumber', i + 1);
|
formData.append('partNumber', i + 1);
|
||||||
formData.append('key', fileName);
|
formData.append('key', key);
|
||||||
|
|
||||||
const chunkResult = await uploadPart(formData);
|
const chunkResult = await uploadPart(formData);
|
||||||
if (!chunkResult.success) {
|
if (!chunkResult.success) {
|
||||||
|
|
@ -797,8 +804,8 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
parts.push({
|
parts.push({
|
||||||
part_number: i + 1,
|
partNumber: i + 1,
|
||||||
etag: chunkResult.data.etag,
|
ETag: chunkResult.data.etag,
|
||||||
});
|
});
|
||||||
|
|
||||||
item.uploadedBytes = end;
|
item.uploadedBytes = end;
|
||||||
|
|
@ -808,7 +815,9 @@
|
||||||
|
|
||||||
// Complete upload
|
// Complete upload
|
||||||
const completeResult = await completeUpload({
|
const completeResult = await completeUpload({
|
||||||
upload_id: item.uploadId,
|
uploadId,
|
||||||
|
key,
|
||||||
|
assetId,
|
||||||
parts,
|
parts,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -832,7 +841,11 @@
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
|
|
||||||
if (item.uploadId) {
|
if (item.uploadId) {
|
||||||
abortUpload({ upload_id: item.uploadId }).catch(console.error);
|
abortUpload({
|
||||||
|
uploadId: item.uploadId,
|
||||||
|
key: item.s3Key,
|
||||||
|
assetId: item.assetId,
|
||||||
|
}).catch(console.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadState.uploadQueue = uploadState.uploadQueue.filter(u => u.id !== id);
|
uploadState.uploadQueue = uploadState.uploadQueue.filter(u => u.id !== id);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue