Skip to content

Commit

Permalink
fix: non latin multipart file upload (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
xvonabur authored May 5, 2021
1 parent 61dc25b commit 896cf32
Showing 1 changed file with 15 additions and 4 deletions.
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

0 comments on commit 896cf32

Please sign in to comment.