Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non latin multipart file upload #210

Merged
merged 1 commit into from
May 5, 2021
Merged
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
19 changes: 15 additions & 4 deletions ios/VydiaRNFileUploader.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ - (void)_sendEventWithName:(NSString *)eventName body:(id)body {
RCT_EXPORT_METHOD(getFileInfo:(NSString *)path resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
{
@try {
NSURL *fileUri = [NSURL URLWithString: path];
// Escape non latin characters in filename
NSString *escapedPath = [path stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet.URLQueryAllowedCharacterSet];

NSURL *fileUri = [NSURL URLWithString:escapedPath];
NSString *pathWithoutProtocol = [fileUri path];
NSString *name = [fileUri lastPathComponent];
NSString *extension = [name pathExtension];
Expand Down Expand Up @@ -242,11 +245,19 @@ - (NSData *)createBodyWithBoundary:(NSString *)boundary

NSMutableData *httpBody = [NSMutableData data];

// Escape non latin characters in filename
NSString *escapedPath = [path stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet.URLQueryAllowedCharacterSet];

// resolve path
NSURL *fileUri = [NSURL URLWithString: path];
NSString *pathWithoutProtocol = [fileUri path];
NSURL *fileUri = [NSURL URLWithString: escapedPath];

NSError* error = nil;
NSData *data = [NSData dataWithContentsOfURL:fileUri options:NSDataReadingMappedAlways error: &error];

if (data == nil) {
NSLog(@"Failed to read file %@", error);
}

NSData *data = [[NSFileManager defaultManager] contentsAtPath:pathWithoutProtocol];
NSString *filename = [path lastPathComponent];
NSString *mimetype = [self guessMIMETypeFromFileName:path];

Expand Down