This repository was archived by the owner on Mar 16, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +43
-14
lines changed
android/src/main/java/com/RNFetchBlob Expand file tree Collapse file tree 4 files changed +43
-14
lines changed Original file line number Diff line number Diff line change @@ -467,9 +467,8 @@ private void done(Response resp) {
467
467
}
468
468
break ;
469
469
}
470
- // if(!resp.isSuccessful())
471
- // resp.body().close();
472
- resp .body ().close ();
470
+ if (!resp .isSuccessful ())
471
+ resp .body ().close ();
473
472
releaseTaskResource ();
474
473
}
475
474
Original file line number Diff line number Diff line change @@ -289,16 +289,27 @@ - (NSDictionary *)constantsToExport
289
289
290
290
}
291
291
292
- RCT_EXPORT_METHOD (cp:(NSString *)path toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback) {
293
- NSError * error = nil ;
294
- path = [RNFetchBlobFS getPathOfAsset: path];
295
- BOOL result = [[NSFileManager defaultManager ] copyItemAtURL: [NSURL fileURLWithPath: path] toURL: [NSURL fileURLWithPath: dest] error: &error];
296
-
297
- if (error == nil )
298
- callback (@[[NSNull null ], @YES ]);
299
- else
300
- callback (@[[error localizedDescription ], @NO ]);
301
-
292
+ RCT_EXPORT_METHOD (cp:(NSString *)src toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback) {
293
+
294
+ // path = [RNFetchBlobFS getPathOfAsset:path];
295
+ [RNFetchBlobFS getPathFromUri: src completionHandler: ^(NSString *path, ALAssetRepresentation *asset) {
296
+ NSError * error = nil ;
297
+ if (path == nil )
298
+ {
299
+ [RNFetchBlobFS writeAssetToPath: asset dest: dest];
300
+ callback (@[[NSNull null ], @YES ]);
301
+ }
302
+ else
303
+ {
304
+ BOOL result = [[NSFileManager defaultManager ] copyItemAtURL: [NSURL fileURLWithPath: path] toURL: [NSURL fileURLWithPath: dest] error: &error];
305
+
306
+ if (error == nil )
307
+ callback (@[[NSNull null ], @YES ]);
308
+ else
309
+ callback (@[[error localizedDescription ], @NO ]);
310
+ }
311
+ }];
312
+
302
313
}
303
314
304
315
RCT_EXPORT_METHOD (mv:(NSString *)path toPath:(NSString *)dest callback:(RCTResponseSenderBlock) callback) {
Original file line number Diff line number Diff line change 63
63
resolver : (RCTPromiseResolveBlock)resolve
64
64
rejecter : (RCTPromiseRejectBlock)reject ;
65
65
// + (void) writeFileFromFile:(NSString *)src toFile:(NSString *)dest append:(BOOL)append;
66
+ + (void ) writeAssetToPath : (ALAssetRepresentation * )rep dest : (NSString *)dest ;
66
67
67
68
// constructor
68
69
- (id ) init ;
Original file line number Diff line number Diff line change 1
- //
1
+
2
2
// RNFetchBlobFS.m
3
3
// RNFetchBlob
4
4
//
@@ -193,6 +193,7 @@ - (void) startAssetReadStream:(NSString *)assetUrl
193
193
194
194
+ (NSNumber *) writeFileFromFile : (NSString *)src toFile : (NSString *)dest append : (BOOL )append
195
195
{
196
+
196
197
NSInputStream * is = [[NSInputStream alloc ] initWithFileAtPath: src];
197
198
NSOutputStream * os = [[NSOutputStream alloc ] initToFileAtPath: dest append: append];
198
199
[is open ];
@@ -730,4 +731,21 @@ + (void) getPathFromUri:(NSString *)uri completionHandler:(void(^)(NSString * pa
730
731
}
731
732
}
732
733
734
+ + (void ) writeAssetToPath : (ALAssetRepresentation * )rep dest : (NSString *)dest
735
+ {
736
+ int read = 0 ;
737
+ int cursor = 0 ;
738
+ Byte * buffer = (Byte *)malloc (10240 );
739
+ NSOutputStream * ostream = [[NSOutputStream alloc ] initToFileAtPath: dest append: NO ];
740
+ [ostream open ];
741
+ while ((read = [rep getBytes: buffer fromOffset: cursor length: 10240 error: nil ]) > 0 )
742
+ {
743
+ cursor+=10240 ;
744
+ [ostream write: buffer maxLength: read];
745
+ }
746
+ [ostream close ];
747
+ free (buffer);
748
+ return ;
749
+ }
750
+
733
751
@end
You can’t perform that action at this time.
0 commit comments