Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-panthers-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tus/azure-store": patch
---

Fix error on saving metadata when it contains non-ASCII characters
10 changes: 9 additions & 1 deletion packages/azure-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type KvStore,
MemoryKvStore,
TUS_RESUMABLE,
Metadata,
} from '@tus/utils'
import {
type AppendBlobClient,
Expand Down Expand Up @@ -78,7 +79,11 @@ export class AzureStore extends DataStore {
await appendBlobClient.setMetadata(
{
tus_version: TUS_RESUMABLE,
upload: JSON.stringify(upload),
upload: JSON.stringify({
...upload,
// Base64 encode the metadata to avoid errors for non-ASCII characters
metadata: Metadata.stringify(upload.metadata ?? {}),
}),
},
{}
)
Expand Down Expand Up @@ -110,6 +115,9 @@ export class AzureStore extends DataStore {
throw ERRORS.FILE_NOT_FOUND
}
const upload = JSON.parse(propertyData.metadata.upload) as Upload
// Metadata is base64 encoded to avoid errors for non-ASCII characters
// so we need to decode it separately
upload.metadata = Metadata.parse(JSON.stringify(upload.metadata ?? {}))

await this.cache.set(appendBlobClient.url, upload)

Expand Down
12 changes: 12 additions & 0 deletions test/src/stores.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ export const shouldCreateUploads = () => {
const upload = await this.datastore.getUpload(file.id)
assert.deepStrictEqual(upload.metadata, file.metadata)
})

it('should store `upload_metadata` with non-ASCII characters', async function () {
const file = new Upload({
id: testId('create-test-non-ascii'),
size: 1000,
offset: 0,
metadata: {filename: '世界_domination_plan.pdf', is_confidential: null},
})
await this.datastore.create(file)
const upload = await this.datastore.getUpload(file.id)
assert.deepStrictEqual(upload.metadata, file.metadata)
})
})
}

Expand Down