views:

63

answers:

1

I have an iPhone app that uses sync services to sync its data with the desktop version, everything is working fine, except for the images.

On the iphone I store an image in the Documents Directory and the path to the file in core data. I set up a transient attribute "image" and checked the sync check box and assigned it as an identity property. I added two methods,

- (NSData *)image;
{
  NSLog(@"%@:%s entered", [self class], _cmd);
  if (image) return image;
  NSString *path = [self primitiveValueForKey:@"pathToFile"];
  if (!path) return nil;
  NSString *myPath = [NSHomeDirectory() stringByAppendingPathComponent:path];
  image = [[NSData alloc] initWithContentsOfFile:myPath];
  return image;
}

- (void)setImage:(NSData *)data
{
    NSLog(@"%@:%s entered", [self class], _cmd);
  NSString *destPath = [self primitiveValueForKey:@"pathToFile"];
  if (!destPath) {
  //Build the path we want the file to be at
  destPath = NSHomeDirectory();
  NSString  *guid = [[NSProcessInfo processInfo] globallyUniqueString];
  NSString  *fpath = [NSString stringWithFormat:@"Documents/%@", guid];
  destPath = [destPath stringByAppendingPathComponent:fpath];
  [self setValue:destPath forKey:@"pathToFile"];
  }
  [data writeToFile:destPath atomically:NO];
  [data retain];
  [image release];
  image = data;
}

- (void)willTurnIntoFault
{
  [image release], image = nil;
}

I thought that, because I added the image attribute in the client description file, it would just put the data in the store file that is sent to ZSync daemon, but I am wrong. And the image data is not transferred

My question is can this be done? or What is the best way to sync image data?

please give me guidance, I have searched and searched but no luck finding any solutions.

thank you

A: 

There was a question about image/binary data syncing in Marcus Zarra's speech on the NSConference.

Basically: If you image is below 100k put it directly inside the object as NSData.

Above 100k and below 1M use an additional entity that stores the data and is linked over a relationship.

Above 1M store a path and the data on disk, like you are doing.

Only the first two approaches benefit, from syncing over zsync. If you go for the third, you will have to bring your data to the other side by other means.

tonklon
I know that. I need to know what those other means are
iAm
why would the image data that is in the truth DB not be sent over to the transient attribute and then store on the iPhone file system, and the path saved in the the pathToFile attribute?
iAm