I am struggling to get the file path from imagePicker and sending it to the server.
This is the attempt to pass over the local path client-side:
NSData *webData = UIImagePNGRepresentation(info[UIImagePickerControllerOriginalImage]);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:@"test.png"];
[webData writeToFile:localFilePath atomically:YES];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager POST:url.absoluteString
parameters:@{@"path": localFilePath}
progress:nil
success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
... //results always in error
This is the backend code snipped receiving the path key (in JavaScript):
var fs = require('file-system');
file {
data: fs.readFileSync(path),
}
However, I always get errors like this:
Error: ENOENT: no such file or directory, open '/Library/Developer/CoreSimulator/Devices...
Is there a problem in my JS-Code? Or what other approach should I use to get the file path? I'd be happy if someone could help me out here.
P.S. other popular existing StackOverflow answers on getting the file path induce the same error code.