init upload module
This commit is contained in:
43
test/upload.ts
Normal file
43
test/upload.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { uploadFiles, UploadProgress } from '../src/query-upload.ts';
|
||||
|
||||
const div = document.createElement('div');
|
||||
div.innerHTML = `
|
||||
<input type="file" id="file" multiple />
|
||||
<button id="upload">上传</button>
|
||||
`;
|
||||
document.body.appendChild(div);
|
||||
|
||||
const upload = document.getElementById('upload');
|
||||
upload.addEventListener('click', () => {
|
||||
const file = document.getElementById('file') as HTMLInputElement;
|
||||
const files = file.files;
|
||||
// console.log(files);
|
||||
const uploadProgress = new UploadProgress({
|
||||
onStart: () => {
|
||||
console.log('开始上传');
|
||||
},
|
||||
onDone: () => {
|
||||
console.log('上传完成');
|
||||
},
|
||||
onProgress: (progress: number, data: any) => {
|
||||
console.log('上传进度', progress);
|
||||
},
|
||||
});
|
||||
uploadFiles(
|
||||
Array.from(files),
|
||||
{
|
||||
appKey: 'test',
|
||||
version: '1.0.0',
|
||||
username: 'test',
|
||||
directory: 'test',
|
||||
},
|
||||
{
|
||||
uploadProgress,
|
||||
token: 'test',
|
||||
createEventSource: (baseUrl: string, searchParams: URLSearchParams) => {
|
||||
return new EventSource(baseUrl + '/api/s1/events?' + searchParams.toString());
|
||||
},
|
||||
FormDataFn: FormData,
|
||||
},
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user