File tree 3 files changed +26
-1
lines changed
3 files changed +26
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @tus/azure-store " : patch
3
+ ---
4
+
5
+ Fix error on saving metadata when it contains non-ASCII characters
Original file line number Diff line number Diff line change 7
7
type KvStore ,
8
8
MemoryKvStore ,
9
9
TUS_RESUMABLE ,
10
+ Metadata ,
10
11
} from '@tus/utils'
11
12
import {
12
13
type AppendBlobClient ,
@@ -78,7 +79,11 @@ export class AzureStore extends DataStore {
78
79
await appendBlobClient . setMetadata (
79
80
{
80
81
tus_version : TUS_RESUMABLE ,
81
- upload : JSON . stringify ( upload ) ,
82
+ upload : JSON . stringify ( {
83
+ ...upload ,
84
+ // Base64 encode the metadata to avoid errors for non-ASCII characters
85
+ metadata : Metadata . stringify ( upload . metadata ?? { } ) ,
86
+ } ) ,
82
87
} ,
83
88
{ }
84
89
)
@@ -110,6 +115,9 @@ export class AzureStore extends DataStore {
110
115
throw ERRORS . FILE_NOT_FOUND
111
116
}
112
117
const upload = JSON . parse ( propertyData . metadata . upload ) as Upload
118
+ // Metadata is base64 encoded to avoid errors for non-ASCII characters
119
+ // so we need to decode it separately
120
+ upload . metadata = Metadata . parse ( JSON . stringify ( upload . metadata ?? { } ) )
113
121
114
122
await this . cache . set ( appendBlobClient . url , upload )
115
123
Original file line number Diff line number Diff line change @@ -71,6 +71,18 @@ export const shouldCreateUploads = () => {
71
71
const upload = await this . datastore . getUpload ( file . id )
72
72
assert . deepStrictEqual ( upload . metadata , file . metadata )
73
73
} )
74
+
75
+ it ( 'should store `upload_metadata` with non-ASCII characters' , async function ( ) {
76
+ const file = new Upload ( {
77
+ id : testId ( 'create-test-non-ascii' ) ,
78
+ size : 1000 ,
79
+ offset : 0 ,
80
+ metadata : { filename : '世界_domination_plan.pdf' , is_confidential : null } ,
81
+ } )
82
+ await this . datastore . create ( file )
83
+ const upload = await this . datastore . getUpload ( file . id )
84
+ assert . deepStrictEqual ( upload . metadata , file . metadata )
85
+ } )
74
86
} )
75
87
}
76
88
You can’t perform that action at this time.
0 commit comments