Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Single file upload
- const file = this.$refs.file.files[0];
- Vapor.store(file, {
- progress: progress => {
- this.uploadProgress = Math.round(progress * 100);
- }
- }).then(response => {
- axios.post('/api/profile-photo', {
- uuid: response.uuid,
- key: response.key,
- bucket: response.bucket,
- name: file.name,
- content_type: file.type,
- })
- });
- // Multi-file upload
- const files = this.$refs.file.files;
- const promises = []
- files.map(f => promises.push(Vapor.store(f, { // multi-progressbar stuff would go here. })
- // Wait for all uploads to complete...
- await Promise.all(promises)
- // Make one post to your api route per file uploaded...
- promises.map((response, index) =>
- axios.post('/api/file', {
- uuid: response.uuid,
- key: response.key,
- bucket: response.bucket,
- name: files[index].name,
- content_type: files[index].type,
- })
- );
- // Or make a single post to an api route that will accept an array of items, and map those accordingly...
- const results = []
- promises.map((response, index) =>
- results.push({
- uuid: response.uuid,
- key: response.key,
- bucket: response.bucket,
- name: files[index].name,
- content_type: files[index].type,
- })
- );
- axios.post('/api/multiple-files', results)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement