In ios7 we can write images to documents directory and access it without any problem.
In IOs8 i am able to write imagesdata to documents directory and access it. The location of images folder changes every time i run the app on the Simulator.I went through many stack overflow questions and apple's Technical Note (link:https://developer.apple.com/library/ios/technotes/tn2406/_index.html) but i didn't get any solution.Actually i am storing the path of images file in sqlite database.
Any help appreciated.
Seems like you are storing the complete path.
In IOS 8 Apple changed the directory structure.Apple extended folders in documents directory internally(i.e something like /developer/data/some random number sequence).Directory folders keeps on changing on every build,if u store the complete path in your sqlite then you do not find any file at the location because the documents directory location has changed.
The solution is do not store the complete path just store the path from documents directory into the database,while accessing images just prefix it with current application documents directory, then you are able to access your images from your apps directory
Example:
//Storing Images
NSString *imagePathString = [NSString stringWithFormat:#“/%#/%#.png”,#“Your Folder name”,#“image name”];
//Store this image path String to database
//Retrieving Images
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:imagePathString];
//This is the path for your images
Related
I have a JavaFX program in which the user may choose a profile picture. This profile picture is applied and should then be saved to a resources folder at the same level as my bin and src folders. I have a few questions:
How do you define the file path? This is my current attempt. I get a NullPointerException, but I think that has something to do with the output stream. It's fixable, so I am mostly worried about the path. This works when accessing an image, so why doesn't it work when saving one?
// Store chosen profile picture
File outputFile = new File("/resources/profilePicture.png");
ImageIO.write(SwingFXUtils.fromFXImage(croppedProfilePicture, null), "png", outputFile);
When I go to deploy the application, will I get issues with saving to a resource folder at the same level as bin and src? Do bin and src even exist when you deploy an application?
Thanks. I can supply any more information if needed.
I'm creating a desktop app using Mozilla's XUL. I created an SQLite database, and stored some data in it. The database was created using:
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var file = FileUtils.getFile("ProfD", ["tickets.sqlite"]);
var dbConn = Services.storage.openDatabase(file);
I tested if the tables really exist using tableExists method, and I got true message. The database should be stored in the profile directory, which is by default located in a hidden folder (I use Fedora, by the way) in the home directory: ~/.mozilla/. Problem is I can't find my database there, stored as tickets.sqlite. Anyone?
If you got a file you can definitively retrieve its path using properties path, nativePath etc. - dump it onto console for example.
See https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFile for more details about nsIFile.
Profile directory appears in app cache, for Linux it is in the home folder, and it's a hidden folder(not sure for WIN). Cache's name is defined in application.spec file, where you define Vendor name and App name, so cache folder is going to be .Vendor and inside it you will find App folder with details. That is the profile dir for Mozilla apps.
I am having a application that uploads files according to the user input..i just want to move that particular file to moved to another folder..
Now i am able to move the files to the destination folder..but it moves all the files which is already there in the folder..
i am creating a folder dynamically while uploading the files..and i need that file to be moved to that created folder...
I need to move only the uploaded file during run time...
E:\Export Documents - Copy\Uploads this path to C:\inetpub\wwwroot
this is my code
Set oFS = Server.CreateObject("Scripting.FileSystemObject")
strDir = "c:\inetpub\wwwroot\" & fldr
oFS.CopyFile "E:\Export Documents - Copy\Uploads\*.jpg", "c:\inetpub\wwwroot\" & fldr
What you probably want to do is identify the file you have just uploaded and then move that. If you are already creating a folder to store the files in in inetpub, you might as well do the same in Uploads, and then just move that folder.
You will probably find it helpful to use fileSystemObject.MoveFolder instead of .CopyFile so that your Uploads folder does not fill up.
If you want some help with how to do that, post the code you are using to upload your file.
For working with the FileSystemObject, this is a useful reference
On another note, is it really wise to move files from Uploads into wwwroot? A malicious user could do some damage in there.
I have a folder that stores images and the paths to the images are stored in the database. There are almost 2500+ employee images stored there.
If I want to change the physical location of the folder that has the images, how do I manage the stored paths in the DB and the virtual path, root and all the related info.
Well, here is what I would do:
Copy your images to the new directory. (Leave the old directory in place for now)
Run a SQL update script on your DB to change the stored location. (Without knowing your db structure I can't say more.)
Update your app code to point to the new directory.
Test your app to verify that is uses the new directory.
Rename the old directory to something else, so that any link to it would break.
See if anything is broken, and fix it!
My host has the following structure:
/Web -> Where is the content of the site
/Data -> Folder permissions to read and write
How do I upload a file to the Data folder?
The code below does not work, since "~" returns the directory / web.
//Save Image
var serverPath = Server.MapPath(Href("~/Data/") + id);
Directory.CreateDirectory(serverPath);
imgOri.Save(Path.Combine(serverPath, fileName));
Server.MapPath() is designed to map a path up to the root directory of the application. As you are trying to upload a file above the root it won't work.
You can upload a file above the root by specifying the exact file path (if the host can provide it):
var serverPath = "C:\YourFolder\Data\") + id);
I'm surprised your host is allowing you to upload a file outside of the root directory as there are a number of dangers in doing this...you may also run into Trust issues.
You can obtain the path to a directory which sits at the same level of your site root by using Server.MapPath as below:
#{
var root = Server.MapPath(".");
var temp = root.Split('\\');
temp[temp.Length - 1] = "Data";
var newpath = string.Join("\\", temp);
}
Hosting companies used to provide "data" directories outside of the root folder as a safe place for things like Access mdb databases. You cannot directly browse to a directory which is outside of the root of your site. ASP.NET did away with the need for these things with the introduction of App_Data. The only reason you would want to use this kind of folder nowadays is if you want to apply some kind of authentication prior to serving the contents of the directory. Then you need to use a handler, or a simple cshtml file will do. You can combine the WebSecurity helper with the WebImage helper to first authenticate the user, and then retrieve and display the image if they pass the test. The src in your img tag will point to the cshtml file, with a querystring or UrlData value so you know which image to display.
If you don't need to validate users prior to displaying image, storing the image files outside of the root adds an unnecessary level of complication.