Skip to content

Commit 43f05bb

Browse files
committed
(demo) fix multiple files upload
1 parent 7ffa4ab commit 43f05bb

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

demo/src/ChatContainer.vue

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -530,48 +530,53 @@ export default {
530530
},
531531
532532
async uploadFile({ file, messageId, roomId }) {
533-
let type = file.extension || file.type
534-
if (type === 'svg' || type === 'pdf') {
535-
type = file.type
536-
}
533+
return new Promise(resolve => {
534+
let type = file.extension || file.type
535+
if (type === 'svg' || type === 'pdf') {
536+
type = file.type
537+
}
537538
538-
const uploadTask = storageService.uploadFileTask(
539-
this.currentUserId,
540-
messageId,
541-
file,
542-
type
543-
)
539+
const uploadTask = storageService.uploadFileTask(
540+
this.currentUserId,
541+
messageId,
542+
file,
543+
type
544+
)
544545
545-
uploadTask.on(
546-
'state_changed',
547-
snap => {
548-
const progress = Math.round(
549-
(snap.bytesTransferred / snap.totalBytes) * 100
550-
)
551-
this.updateFileProgress(messageId, file.localUrl, progress)
552-
},
553-
_error => {},
554-
async () => {
555-
const url = await storageService.getFileDownloadUrl(
556-
uploadTask.snapshot.ref
557-
)
546+
uploadTask.on(
547+
'state_changed',
548+
snap => {
549+
const progress = Math.round(
550+
(snap.bytesTransferred / snap.totalBytes) * 100
551+
)
552+
this.updateFileProgress(messageId, file.localUrl, progress)
553+
},
554+
_error => {
555+
resolve(false)
556+
},
557+
async () => {
558+
const url = await storageService.getFileDownloadUrl(
559+
uploadTask.snapshot.ref
560+
)
558561
559-
const messageDoc = await firestoreService.getMessage(
560-
roomId,
561-
messageId
562-
)
562+
const messageDoc = await firestoreService.getMessage(
563+
roomId,
564+
messageId
565+
)
563566
564-
const files = messageDoc.data().files
567+
const files = messageDoc.data().files
565568
566-
files.forEach(f => {
567-
if (f.url === file.localUrl) {
568-
f.url = url
569-
}
570-
})
569+
files.forEach(f => {
570+
if (f.url === file.localUrl) {
571+
f.url = url
572+
}
573+
})
571574
572-
firestoreService.updateMessage(roomId, messageId, { files })
573-
}
574-
)
575+
await firestoreService.updateMessage(roomId, messageId, { files })
576+
resolve(true)
577+
}
578+
)
579+
})
575580
},
576581
577582
updateFileProgress(messageId, fileUrl, progress) {

0 commit comments

Comments
 (0)