Couchbase Lite Error When Converting NSDAta to UIImage in iOS

Hi ,

When I try to convert NSData to UIImage . Image is showing nil value.
Could you please help me. My code is below.

CBLDocument* doc = [CBObjects.sharedInstance.database documentWithID:@"Attach_sample4"];
    
       
    CBLRevision* rev = doc.currentRevision;
    CBLAttachment* att = [rev attachmentNamed: @"a5"];
 

    
   
    
    
    if (att != nil) {
        NSData* imageData = att.content;
        
        NSString *base64String = [imageData base64EncodedStringWithOptions:0];
        
        NSData *dataFromString = [[NSData alloc] initWithBase64EncodedString:base64String options:0];

//       UIImage *rainyImage = [UIImage imageNamed:@"rainy.jpg"];
//        
//        
//        NSData *imgData = UIImageJPEGRepresentation(rainyImage, 0.9);
//        
//        
//        UIImage *photo2 = [UIImage imageWithData:imgData];
        
        UIImage *photo = [UIImage imageWithData:dataFromString];
        
        
        NSLog(@"%@",photo);

Thanks in advance!!

That code takes the attachment data, converts it to base64, then converts it back into data. There’s no need to do that; it’s a no-op.

I don’t know why creating the UIImage fails. Have you set a breakpoint and looked at the contents of imageData? If it’s JPEG, the start of the data will look something like this; some of the bytes may be different but it will have ASCII JFIF in it:

00000000  ff d8 ff e0 00 10 4a 46  49 46 00 01 01 01 02 58  |......JFIF.....X|

Thanks. The problem was while saving file in COuhbase Server.

It was like this
"content_type": “multipart/form-data; boundary=----WebKitFormBoundaryvEOCQBzSDENRvKXs”,

but it should need to be like this

“content_type”: “image/jpeg”,