ShiminCai

Error Posting Attachment To Server

Discussion created by ShiminCai on Feb 20, 2014
Latest reply on Dec 23, 2014 by ccole3390
Hi there,

I'm adding a photo attachment to a feature and posting it to the server but unable to do it due to a network error that I couldn't figure out... Please help.

In the Image Picker delegate method, the attachment is added to the feature attachmentManager and posted to the server:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

if ([mediaType isEqualToString:(NSString*)kUTTypeImage])
    {
  // once they take/choose a picture, add it to the attachments collection and reload the table data
  UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
 
            NSString *photoName = [@"Photo " stringByAppendingString:[NSString stringWithFormat:@"%d", [_attachmentManager.attachments count] + 1 ]];

            [_attachmentManager addAttachmentAsJpgWithImage:image name:photoName];
           
            if([_attachmentManager hasLocalEdits])
            {
                [_attachmentManager postLocalEditsToServer];
            }
           
        }

[self.tableView reloadData];
   
    [self dismissViewControllerAnimated:YES completion:NULL];
}

In the feature attachment manager delegate method, the attachment.networkError occurs:
-(void)attachmentManager:(AGSAttachmentManager *)attachmentManager didPostLocalEditsToServer:(NSArray *)attachmentsPosted
{
    //loop through all attachments looking for failures
    BOOL _anyFailure = NO;
    NSString* reason;
   
    for (AGSAttachment* attachment in attachmentsPosted)
    {
        if(attachment.networkError!=nil || attachment.editResultError!=nil)
        {
            _anyFailure = YES;

            if(attachment.networkError!=nil)
            {
                reason = [@"Network Error: " stringByAppendingString:[attachment.networkError localizedDescription]];
                NSLog(@"LocalizedDescription: %@", attachment.networkError.localizedDescription);
                NSLog(@"Description: %@", attachment.networkError.description);
                NSLog(@"LocalizedFailureReason: %@", attachment.networkError.localizedFailureReason);
                NSLog(@"UserInfo.Description: %@", attachment.networkError.userInfo.description);
               
            }
            else if(attachment.editResultError !=nil)
            {
                reason = [@"Edit Result Error: " stringByAppendingString: attachment.editResultError.errorDescription];
            }
        }
    }
   
    if(_anyFailure)
    {
        //warn the user
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning: Unable to post attachment to server"
                                                        message:reason
                                                       delegate:nil
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles:nil];
       
        [alert show];
    }
}

The NSLog details are:
2014-02-21 12:09:43.062 FCMapApp[2440:60b] LocalizedDescription: Empty username/password
2014-02-21 12:09:43.064 FCMapApp[2440:60b] Description: Error Domain=NSCocoaErrorDomain Code=401 "Empty username/password" UserInfo=0x166c4850 {NSURL=http://203.8.108.21/arcgis/rest/services/FeatureServices/BioData/FeatureServer/0/1/addAttachment, NSLocalizedDescription=Empty username/password}
2014-02-21 12:09:43.067 FCMapApp[2440:60b] LocalizedFailureReason: (null)
2014-02-21 12:09:43.069 FCMapApp[2440:60b] UserInfo.Description: {
    NSLocalizedDescription = "Empty username/password";
    NSURL = "http://203.8.108.21/arcgis/rest/services/FeatureServices/BioData/FeatureServer/0/1/addAttachment";
}

Do we need a usename/password to edit a feature service?

I tried the OfflineFeatureEdittingSample and it does not work either on the live mode. However, on the local mode it can save the photo to the local replica geodatabase and later sync it to the live server...

Any help is much appreciated. I'm using SDK 10.2.1 and ArcGIS Server 10.2.1 sync-enabled feature service.

Kind regards,

Shimin

Outcomes