This question already has an answer here:
What is the hexadecimal part in the Documents folder's path?
(1 answer)
Closed 5 years ago.
Recently I realize that in URL path to local file one path element changed: /private/var/mobile/Containers/Data/Application/A6ED77D7-3A57-47BC-BD41-B1F857529D0F I mean A6ED77D7-3A57-47BC-BD41-B1F857529D0F sometimes it stay the same and sometimes it is different than before.
I found this when after I save the whole path in db I wasn't able to read a file again because FileManager said that file doesn't exist.
I'd like to ask what this id is, when it changes?
That is just a path to the documents directory which will be changed everytime you run the application. Following would be helpful for you: FileManager says file doesn't exist when it does
Related
This question already has answers here:
How to put an image in a Realm database?
(2 answers)
Closed 7 years ago.
I would like to know if it is possible to save an image to realm database.
If yes, how can I do that?
I understand Swift only!
Thank you in advance
The best way to save images and other kind of data in this case is to store only the URL to the file in the database. Attention: URL does NOT mean a remote URL.
For example, if you want to persist your image, you can create a folder in the Documents folder, and save any image there, with a random name or whatever you prefer.
Here's how to access the Documents folder using Swift:
let documentsPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsPath = documentsPaths.first
Then in your Realm, store only the path to the file ("/images/1R9RI8S.jpg").
That way, you can always retrieve your image file by fetching the Documents folder, plus your Realm is not bloated with large data, plus the content of the Documents folder is backed up by iOS.
You can store images as NSData if images are small in size or less in numbers. However, if you have more images or large size store only paths.
Look at the related answer link
Recently I've ran into a big problem with pugiXml (used within cocos2d-x engine).
Shortly, I've made a quiz game (in mentioned Cocos2d-x). I keep my questions (and some other data) in an Xml file. On new game they get parsed and inserted into dictionaries. If a question is answered, a short string indicating the answer (whether it was good or not - Y/N) is inserted into that Xml file (below that particular question). Later, I use this data to show statistics (I count the percentage of questions with good answers - which is counting the amount of Y's divided by the amount of questions, multiplied by 100).
I use:
CCFileUtils::sharedFileUtils()->fullPathForFilename(o_QA);
to get the file and later
pBuffer = CCFileUtils::sharedFileUtils()->getFileData(fullPath.c_str(), "rb", &bufferSize);
to put file into buffer and
pugi::xml_parse_result result = doc.load_buffer(pBuffer,bufferSize);
to parse data and start working on it.
Finally, I save the file with:
doc.save_file(fullPath.c_str());
Android:
It's working very well, although I had to copy the file with questions to /data/data/app/Files/ . Still, It's keeping the changes on many devices.
iOS:
Unfortunately, on iOS it's not working. Data get loaded and parsed (which means, that I can actually play the game), but they are not saved. I've tried moving the files to other folders (started from Resources/Documents, then main Resources folder, Resources/Library/Application Support). It's still not saving the data and I don't know what to do. The result is my statistics not being counted well (it doesn't matter how you answer the questions - all of them are false, because the Xml file is not being updated).
Did anyone run into similar problem?
Can you, please, help me?
I am doing something similar in my own app, using both pugixml and cocos2d-x. So I can confirm this combination works well.
Rather, because on iOS you cannot both read and write the data from and to the app bundle (which is read only), you will need to implement a simple check in the writable document directory - If you a saved file there, load it, if not, load from the app bundle.
So in essence for loading, if your saved filename is "my_save.xml", here is an example flow:
1) Construct a path for your save file in the writable folder by concatenating the writable folder path + your filename. CCFileUtils should have something like getWritablePath() for that.
2) if the file exists in the folder, load it. Otherwise, go to 3).
3) Construct a path to your original data file from the app bundle, using CCFileUtils::sharedFileUtils()->fullPathForFilename(). Load the file from there.
For saving, simply do step 1 and save the file there.
I need help getting access to the documents directory using only C on iOS.
I have my .c file looking for a specific file in the application bundle. I have no problem accessing this file. It looks like this: fopen("filename",
Unfortunately, if I want to move that file to the documents directory, appending "/Documents/filename" doesn't work.
I know how to access the file using an objective-c class, easily, using filesystemrepresentation. But I don't know how to do it only in C. Any help would be greatly appreciated!
Thanks!
Fopen defaults to the directory that the executable file is in, ".app/" - on iOS.
I was able to get to the documents directory by making a char of the Current Working Directory and then removing the last couple characters of the char to get out of the ".app/" bundle and then appending the Documents path to the end of it.
This question already exists:
Closed 10 years ago.
Possible Duplicate:
Issues in Internet Explorer 9
IE->not reading file and as in firefox----> s(input_id).files is giving file details and IE----> it is null or undefined value. so let me know how to read file in IE. how do i get file size, file name etc in IE9
I assume that you are trying to access the FileList on the client side using something like document.getElementById("input_id").files.
The files method is part of the File API and not supported by IE9. However, IE10 supports it.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
How can I use Delphi to test if a Directory is writeable?
My program will download an update for the user if they request it. The user has to specify the location to save the installer. They might pick a directory which they don't have access to save something to. In this case the download starts (downloading to a temporary directory I assume) and we only know that it failed when it ends and tries to move the file into the folder.
Is there a simple way to check if we have write permissions on a folder in Delhi?
There is AccessCheck function or tricks, but this information is not reliable in generic case.
So, usually you just need to create file to check, if you have access for that.
For your specific case, you have the following choices:
After save dialog closing: try to
create a file in target folder with
the name of downloading file. Delete
it after check. Not pretty, since
you rarely may have access to create
files, but not to delete them.
After save dialog closing: try to create a
file in target folder with the name
of downloading file. Keep that
handle open and move file content to
it after download is complete. Not
pretty, since you can't move file,
you need to copy it.
(the right one?) Just bring save dialog again
on any access denied issues.