Skip to content

Commit

Permalink
[PAY-3691] Sanitize upload filename for react-native (#10707)
Browse files Browse the repository at this point in the history
  • Loading branch information
sliptype authored Dec 12, 2024
1 parent 8c4ea49 commit 673e8bb
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/sdk/src/sdk/services/Storage/Storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,22 @@ export class Storage implements StorageService {
Object.keys(options).forEach((key) => {
formData.append(key, `${options[key]}`)
})

const formDataFile =
'uri' in file
? {
...file,
// NOTE this is required for react-native
// certain characters in the file name make formData invalid
name: file.name
? encodeURIComponent(file.name.replace(/[()]/g, ''))
: 'blob'
}
: file

formData.append(
'files',
isNodeFile(file) ? file.buffer : file,
isNodeFile(formDataFile) ? formDataFile.buffer : formDataFile,
file.name ?? 'blob'
)

Expand Down

0 comments on commit 673e8bb

Please sign in to comment.