@@ -84,13 +84,15 @@ export function useBlob (name: string = '') {
84
84
const bucket = useBucket ( name )
85
85
86
86
const type = file . type || getContentType ( file . filename )
87
- const extension = getExtension ( type )
88
- // TODO: ensure filename unicity
89
- const filename = [ randomUUID ( ) , extension ] . filter ( Boolean ) . join ( '.' )
87
+ // TODO: ensure key unicity
88
+ const key = randomUUID ( )
90
89
const httpMetadata = { contentType : type }
91
- const customMetadata = getMetadata ( type , file . data )
90
+ const customMetadata : Record < string , any > = {
91
+ ...getMetadata ( type , file . data ) ,
92
+ filename : file . filename
93
+ }
92
94
93
- return await bucket . put ( filename , toArrayBuffer ( file . data ) , { httpMetadata, customMetadata } )
95
+ return await bucket . put ( key , toArrayBuffer ( file . data ) , { httpMetadata, customMetadata } )
94
96
}
95
97
} ,
96
98
async delete ( key : string ) {
@@ -109,10 +111,6 @@ function getContentType (pathOrExtension?: string) {
109
111
return ( pathOrExtension && mime . getType ( pathOrExtension ) ) || 'application/octet-stream'
110
112
}
111
113
112
- function getExtension ( type ?: string ) {
113
- return ( type && mime . getExtension ( type ) ) || ''
114
- }
115
-
116
114
function getMetadata ( type : string , buffer : Buffer ) {
117
115
if ( type . startsWith ( 'image/' ) ) {
118
116
return imageMeta ( buffer ) as Record < string , any >
0 commit comments