11<template >
22 <div class =" ic-fb_uploader" >
33 <ul class =" ic-fb_uploader-files" >
4- <li v-for =" fileRef in sentFiles" :key =" fileRef.fullPath" >
5- {{fileRef.name}}
4+ <li v-for =" file in sentFiles" :key =" file.ref.fullPath" >
5+ <a
6+ target =" _blank"
7+ :href =" file.downloadUrl"
8+ @click =" onFileLinkClick(file.ref, $event)" >
9+ {{file.ref.name}}
10+ </a >
611 </li >
712 </ul >
813 <input
@@ -60,6 +65,20 @@ export default {
6065 onBtnClick () {
6166 this .$refs .loader .click ()
6267 },
68+ onFileLinkClick (fileRef , event ) {
69+ /**
70+ * When user clicks in a file link, event contains
71+ * fullPath and the getDownloadURL function that when is
72+ * called returns a promise of the url.
73+ * @event click
74+ * @type {Object}
75+ */
76+ this .$emit (' click' , {
77+ ... event ,
78+ fullPath: fileRef .fullPath ,
79+ getDownloadURL: fileRef .getDownloadURL ,
80+ })
81+ },
6382 onChangeLoader (event ) {
6483 const files = event .target .files
6584 const curFilesLength = this .sentFiles .length + files .length
@@ -84,21 +103,38 @@ export default {
84103 /**
85104 * This event is called before each file upload begins
86105 * call doUpload to begin upload. Properties in the
87- * payload: fullPath, remainingFiles, file and doUpload.
106+ * payload: fullPath, file and doUpload.
88107 * @event upload
89108 * @type {Object}
90109 */
91110 this .$emit (' upload' , {
92111 fullPath: fileRef .fullPath ,
93- remainingFiles: files .length - index,
94112 file,
95113 doUpload: this .getUploadFn (fileRef, file)
96114 })
97115 },
98116 getUploadFn (fileRef , file ) {
99117 return () => {
100118 fileRef .put (file)
101- .then (() => this .sentFiles .push (fileRef))
119+ .then (() => fileRef .getDownloadURL ())
120+ .then (downloadUrl => {
121+ this .sentFiles .push ({
122+ ref: fileRef,
123+ downloadUrl,
124+ })
125+
126+ /**
127+ * This event is called after each file upload ends.
128+ * Properties in the payload: fullPath and the getDownloadURL
129+ * function that when is called returns a promise of the url.
130+ * @event uploaded
131+ * @type {Object}
132+ */
133+ this .$emit (' uploaded' , {
134+ fullPath: fileRef .fullPath ,
135+ getDownloadURL: fileRef .getDownloadURL
136+ })
137+ })
102138 .catch (err => this .$emit (' error' , err))
103139 }
104140 }
0 commit comments