I am developing app where local files are stored in user phone's file system. When I try to check if file exists with
var info = await FileSystem.getInfoAsync(`${AppConstants.APP_FOLDER}/main.png`);
console.log(info.exists);
It will print true. But if I try to read contents of file after checking:
var content = await FileSystem.readAsStringAsync(`${AppConstants.TILE_FOLDER}/main.png`);
console.log(content.length);
It freezes and nothing will be printed. I've tested my app on IOS in Expo Go.
The filepath is like that: file:///var/mobile/Containers/Data/Application/.../app_folder/main.png
File system works properly with loading online files by url and images can be shown, while in my case they can't. How should I solve my problem? What additional data I need to provide? Thanks.
This isn't really an answer. But, I had something similar happen to me. You can't really trust console.log() to tell you what code is executing.
I was reading in a file and then processing the data within it. It appeared as if the FileSystem.readAsStringAsync() was hanging because my console.log() message that was directly after the FileSystem call was not being printed. But, it turned out that the problem was inside my processing code.
Once I focused on my processing code, I found the problem and corrected it. Perhaps this is what's happening in your case?
Related
I have an app that lets the user pick local files and send them to the backend to add to their vault. To pick the file, I use FilePicker.platform.pickFiles. It seems to work fine, the file is picked and when it's an image we show a preview to the user (and it always works).
Once the user has picked all their files, we create a list of Future to try and send the files to the backend, then we await the list to resolve. If we deem a picture is too big, we reduce the size using FlutterImageCompress.compressAndGetFile.
This usually works, but on iPhone, there is a seemingly random behavior where the file isn't found and an error is thrown : Cannot retrieve length of file, path = '/private/var/mobile/Containers/Data/Application/3600F812-FD42-4441-A654-766991E45E04/tmp/com.feykro.myApp.int-Inbox/myFile.pdf' (OS Error: No such file or directory, errno = 2)
The file in the example works just fine in other instances, the problem seems random and not directly tied to the file I chose. The problem is not exclusive to pdf files either, as it also occurs on images even though they're picked correctly and displayed in the app.
Any idea what could be causing this ?
Thanks in advance !
I require showing applications in the IOS device capable of opening various file formats.I tried using react native share to achieve the same but options of copying file to other apps did not appear.So i tried using react native fetch blob. RNFetchBlob.fs.exists(fs.dirs.DocumentDir+'/sample.pdf') return true , meaning the file does exist but when i use RNFetchBlob.ios.openDocument(fs.dirs.DocumentDir+'/sample.pdf') nothing happens, not even an error but rather the success callback is called. Appreciate any help.
I was able to resolve the issue , but i don't know why it actually happened in the first place. I used an Alert.alert to find if the file existed or not and then called the RNFetchBlob.ios.openDocument function, upon removing the alert just before the function call it started working.Posting this answer incase it does happen to anyone else.
First post on StackOverflow, after extensively using it for a long time.
I'm building a small app (just to lear swift), and I have troubles with making some data persistent. I use NSCoding to achieve that. The problem is that when saving, the function NSKeyedArchiver.archiveRootObject() return true (so apparently it worked), but when, later, I try to retrieve these saved informations, the result of NSKeyedUnarchiver.unarchiveObjectWithFile() is nil.
Without posting all my code, I was just wondering if it were possible to explore the file in which persistent data are stored during a debug session. That would allow me to check whether I have a problem with the saving or the loading part of the process, and see if the data are indeed stored in the right file.
Thanks,
Lb
Per Apple Documentation, you get a nil with unarchiveObjectWithFile when there is no file at the mentioned path. I would advise to check your file path where you are archiving and saving your object.
As for the debugging, follow this:
Print the file path when you are archiving and saving the object. So in this NSKeyedArchiver.archiveRootObject(myObject, toFile: filePath) print filePath.
Open your terminal app and execute open <filePath> command to open the file path where data is being saved.
Check out if your data file is created in there with right archiving.
I preview docs in my app using a UIDocumentInteractionController. However, sometimes documents show fine, other times the interactioncontroller displays a message "Error while reading the document". I know it is not an issue with the document, because the same document sometimes shows and sometimes doesn't.
Restarting the device solves this problem temporarily - so it would appear to be a memory issue, but strangely I am not getting any memory warnings. Any ideas on how to get this to work reliably please?
Notes:
The documentinteractioncontroller preview is dismissed and the
controller released when finished to ensure prior previews do not
remain in memory
I had the same issue using the quicklook controller
After much testing it appears this issue is limited to iPad 1. The only workaround is a restart.
Since you believe that the document in question is correct, and you believe your code is correct, you have to start looking for other factors. Two that come to mind are:
The state of the application. Is there something about the current state of the app that could be preventing the preview from working? You mentioned that you don't get any memory warnings, but have you looked at how much memory the app is using when the preview succeeds and when it fails?
The state of the document. Is it possible that the file can't be opened for some reason, such as the file already being open? Can you open the file by any other means?
It's possible that your app is trying to display the doc before the os has finished writing it to the sandbox dir. The speed of this operation will be somewhat dependent on what else is going on the the background (other apps, email downloading, iOS checking for updates, etc.). This would also explain why restarting the device can seem to fix the problem temporarily.
To check this, you could check for this error and then try again to open the doc after a few seconds.
Without specific code or or logs, it's tough to say much more.
I am using appfile:/. The path is correct; if I put it on screen and copy-paste it in the explorer it links to the image.
Is there anything else I need to do?
UPDATED I have updated the library, now is more easy to use. Can you test it?
I am the author of the StageWebViewBridge class. There is a known problem if you are using Android. Anyway, I have a working solution I will update the next week.
If the problem is not in Android, then send me some code.
I am also confused on how to access locally packaged assets. I put them in the HTML folder as requested and when I send a signal to the StageWebViewBridge to set the .src attribute of a video I'm not sure how to do it.
Without StageWebViewBridge and entirely in a website I can just reference the file for a video object via JavaScript directly e.g. swvRef.src = 'file.mp4';. This works perfectly fine. When I try to tell flash to send a call via StageWebViewBridge it does receive the call to the StageWebView (I have JavaScript reporting it). However when I try to set the .src of a video object I can't figure out the correct path.
The documentation says to put all things in a 'html' folder. I did so. No reference to a .src of 'html/a.mp4' or 'a.mp4' or 'htmlCache/a.mp4' ever makes the new javascript html5 video class work.
Bridge otherwise is working perfectly sending AS->JS and JS->AS. I'm just looking for info on how to reference packaged files. I want to play a video I put in the /html folder and so far, I just can't do it.
Got the same issue and fixed it with "appfile:/"
Why do you require "appfile:/ for a local html file ?
If the treated html/js/css is local and asset is relative (aka ../ or no http://) you should treat them as "appfile:/" ?
If the treated file is distant you do not have to handle assets ?
Is there a best practice to work with "appfile:/" ?
Actually I debug my html/js/css game in the browser but if I use appfile:/ it will no longer works. I will have to handle 2 behaviors.