Vydia / react-native-background-upload

Upload files in your React Native app even while it's backgrounded. Supports Android and iOS, including camera roll assets.
MIT License
723 stars 330 forks source link

Fix non latin multipart file upload #210

Closed xvonabur closed 3 years ago

xvonabur commented 4 years ago

Summary

Current implementation of multipart file upload and getFileInfo on iOS doesn't support file names with non latin characters. This PR solves it. BTW, Android works fine with useUtf8Charset: true.

Uploading file with non latin characters in filename results in empty NsData and incorrect httpBody content.

To use non latin filenames you need to do 2 things:

  1. Escape filepath

Original file path: file:///private/var/mobile/Containers/Data/Application/A027BF30-70BE-4936-8233-08CED19F0B67/tmp/com.example.app-Inbox/Файл.pdf

Escaped file path: file:///private/var/mobile/Containers/Data/Application/A027BF30-70BE-4936-8233-08CED19F0B67/tmp/com.example.app-Inbox/%D0%A4%D0%B0%D0%B9%D0%BB.pdf

  1. Change method of loading file

I've failed to use NSFileManager contentsAtPath as file loader, so I had to change it to NSData dataWithContentsOfURL. According to Apple iOS SDK comments, it's the preferred way to do it. I'm not an expert, so I'm open to other alternatives.

Test Plan

What's required for testing (prerequisites)?

Rename any pdf file on your iOS device to Файл.pdf

What are the steps to reproduce (after prerequisites)?

Try to upload Файл.pdf with uploadType='multipart'. It will send incorrect http body. Try to getFileInfo of Файл.pdf. It will return an error.

Compatibility

OS Implemented
iOS
Android
github-actions[bot] commented 3 years ago

:tada: This PR is included in version 6.2.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket: