Question

I am trying to copy image and media files using NSStreams. I can not use NSFileManager copyItemAtPath, as I have to copy the file using streams.

The data is transferred over the network and the stream is read by a Python script that writes the data to a file. This worked fine on Mac OSX but when I tried in iOS,the file was not saved in the proper format.

I am able to copy all the files, but some of the metadata like dimensions (for image and media files), and duration (for media files) is missing in the copied file, and the kind is always Document. The other metadata is fine.

When I try to read the file attributes using the NSFileManager

[[NSFileManager defaultManager] attributesOfItemAtPath:@"filePath" error:&error];

It shows an error in the console:

The operation couldn't be completed. No such file or directory

I also observed that all the copied files, irrespective of the file extension (.png,.jpeg,.mov, .zip), has a kind of Document

How do I copy the source image metadata into the copied file?

Are there any Xcode optimizations I need to turn off?

  • OS : Mac OSX 10.8.4, iOS 6

  • Xcode : 4.6.3

Was it helpful?

Solution 2

I found out it is an issue with file extension.Some junk characters appended after the file extension( something like 1.png\\\)

OTHER TIPS

This works for me for any type of file:

if (![NSFileManager.defaultManager copyItemAtPath: sourceFileName toPath: targetFileName error: &error]) {
    NSAlert *alert = [NSAlert alertWithError: error];
    [alert runModal];
    return;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top