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 {
55
55
RCT_EXPORT_METHOD (getFileInfo:(NSString *)path resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject)
56
56
{
57
57
@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];
59
62
NSString *pathWithoutProtocol = [fileUri path ];
60
63
NSString *name = [fileUri lastPathComponent ];
61
64
NSString *extension = [name pathExtension ];
@@ -242,11 +245,19 @@ - (NSData *)createBodyWithBoundary:(NSString *)boundary
242
245
243
246
NSMutableData *httpBody = [NSMutableData data ];
244
247
248
+ // Escape non latin characters in filename
249
+ NSString *escapedPath = [path stringByAddingPercentEncodingWithAllowedCharacters: NSCharacterSet .URLQueryAllowedCharacterSet];
250
+
245
251
// 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
+ }
248
260
249
- NSData *data = [[NSFileManager defaultManager ] contentsAtPath: pathWithoutProtocol];
250
261
NSString *filename = [path lastPathComponent ];
251
262
NSString *mimetype = [self guessMIMETypeFromFileName: path];
252
263
You can’t perform that action at this time.
0 commit comments