FileSystem.copyAsync- file name with a space

I am taking a user-supplied name and saving a file to the document directory. When the user has a space in the name (i.e., “Empty Space” instead of “EmptySpace”), I get the error:
“error from copy: Error: Need a to location.
at createErrorFromErrorData (d4985b2c-2288-47ed-8…d-43de5f737457:2381)”

my code:
try {
const recordingToPath = ${FileSystem.documentDirectory}${ this.state.drillName }.caf;

  await FileSystem.copyAsync({
    from: this.state.fileInfo,
    to: recordingToPath
} catch (error) {
  console.log("error from copy: ", error);

When in the debugger, the “recordingToPath” shows:
file:///…Documents/ExponentExperienceData/%2540ldwight%252Faudiofg/Empty space.caf

I tried encodeURI, but that didn’t work (though I got a different error).

How can I save the file name as entered by the user?

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.