File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,10 @@ - (void)_sendEventWithName:(NSString *)eventName body:(id)body {
5555RCT_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
You can’t perform that action at this time.
0 commit comments