i am using the code below to save an image in the NSDocumentDirectory
-(BOOL)saveImage:(UIImage *)image name:(NSString *)name{
NSString *dir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [NSString pathWithComponents:[NSArray arrayWithObjects:dir, name, nil]];
BOOL ok = [[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
if (!ok) {
NSLog(@"Error creating file %@", path);
}
else {
NSFileHandle* myFileHandle = [NSFileHandle fileHandleForWritingAtPath:path];
[myFileHandle writeData:UIImagePNGRepresentation(image)];
[myFileHandle closeFile];
}
return ok;
}
the name is usually the url of where the image was downloaded.
is there a constraint on the length of the file name? you know sometimes urls may be super long...
thank you
The Windows API imposes a maximum filename length such that a filename, including the file path to get to the file, can't exceed 255-260 characters.
In Windows 10, you can enable long file name support, which allows file names up to 32,767 characters (although you lose a few characters for mandatory characters that are part of the name). To enable this, perform the following: Start the registry editor (regedit.exe)
Detailed Solution. The correct answer is 8. The older MS-DOS FAT file system allows for a maximum of 8 characters in the basic file name and 3 characters in the extension, for a total of 12 characters with the dot separator. An 8.3 file name is what it's called.
We went from an old, limited, file system to something called the New Technology File System (NTFS). NTFS took us to a point where a filename could be 255 characters long, and the file path length could potentially go up to 32,767 characters.
Taking a look at the PATH_MAX constant in syslimits.h:91
...
#define PATH_MAX 1024 /* max bytes in pathname */
...
You can test this yourself by doing :
NSLog(@"%i", PATH_MAX);
just to make sure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With