Skip to content

Commit 896cf32

Browse files
authored
fix: non latin multipart file upload (#210)
1 parent 61dc25b commit 896cf32

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

ios/VydiaRNFileUploader.m

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ - (void)_sendEventWithName:(NSString *)eventName body:(id)body {
5555
RCT_EXPORT_METHOD(getFileInfo:(NSString *)path resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
5656
{
5757
@try {
58-
NSURL *fileUri = [NSURL URLWithString: path];
58+
// Escape non latin characters in filename
59+
NSString *escapedPath = [path stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet.URLQueryAllowedCharacterSet];
60+
61+
NSURL *fileUri = [NSURL URLWithString:escapedPath];
5962
NSString *pathWithoutProtocol = [fileUri path];
6063
NSString *name = [fileUri lastPathComponent];
6164
NSString *extension = [name pathExtension];
@@ -242,11 +245,19 @@ - (NSData *)createBodyWithBoundary:(NSString *)boundary
242245

243246
NSMutableData *httpBody = [NSMutableData data];
244247

248+
// Escape non latin characters in filename
249+
NSString *escapedPath = [path stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet.URLQueryAllowedCharacterSet];
250+
245251
// resolve path
246-
NSURL *fileUri = [NSURL URLWithString: path];
247-
NSString *pathWithoutProtocol = [fileUri path];
252+
NSURL *fileUri = [NSURL URLWithString: escapedPath];
253+
254+
NSError* error = nil;
255+
NSData *data = [NSData dataWithContentsOfURL:fileUri options:NSDataReadingMappedAlways error: &error];
256+
257+
if (data == nil) {
258+
NSLog(@"Failed to read file %@", error);
259+
}
248260

249-
NSData *data = [[NSFileManager defaultManager] contentsAtPath:pathWithoutProtocol];
250261
NSString *filename = [path lastPathComponent];
251262
NSString *mimetype = [self guessMIMETypeFromFileName:path];
252263

0 commit comments

Comments
 (0)