Attach multiple files to node #99

Closed
ovosodo opened this Issue Sep 26, 2013 · 1 comment

Projects

None yet

2 participants

@ovosodo
ovosodo commented Sep 26, 2013

Hi,

I'm uploading and attaching files to a node which could have multiple image atteached but when a i do nodeUpdate, Services overwrite previous images references with the just uploaded one, not adding to them.

I also tried to update a node with an array of fids but only the first in the array is attached.

Here the code i'm using:

NSMutableDictionary *nodeData = [NSMutableDictionary new];
[nodeData setObject:@"151" forKey:@"nid"];

NSData *imgData = UIImageJPEGRepresentation([UIImage imageNamed:@"1.jpg"], 0.5);

NSMutableDictionary *file = [[NSMutableDictionary alloc] init];
NSString *base64Image = [imgData base64EncodedString];
[file setObject:base64Image forKey:@"file"];
NSString *timestamp = [NSString stringWithFormat:@"%d", (int)[[NSDate date] timeIntervalSince1970]];
NSString *imageTitle = @"immagine10002";
NSString *filePath = [NSString stringWithFormat:@"%@%@.jpg",@"public://libera/", imageTitle];
NSString *fileName = [NSString stringWithFormat:@"%@.jpg", imageTitle];
[file setObject:filePath forKey:@"filepath"];
[file setObject:fileName forKey:@"filename"];
[file setObject:timestamp forKey:@"timestamp"];
NSString *fileSize = [NSString stringWithFormat:@"%d", [imgData length]];
[file setObject:fileSize forKey:@"filesize"];
[DIOSFile fileSave:file success:^(AFHTTPRequestOperation *operation, id responseObject) {
    [file setObject:[responseObject objectForKey:@"fid"] forKey:@"fid"];
    [file removeObjectForKey:@"file"];

    NSDictionary *fidLangDict = [NSDictionary dictionaryWithObject:@[file] forKey:@"und"]; 
    [nodeData setObject:fidLangDict forKey:@"field_foto"];

    [DIOSNode nodeUpdate:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject2) {
        X2Log(@"response = %@", responseObject2);


    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        X2Log(@"response = %@", error);
    }];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Something went wrong: %@", [error localizedDescription]);
}];

To attach multiple file i tried to pass a test array of fids in fidLangDict like:

NSDictionary *fidLangDict = [NSDictionary dictionaryWithObject:files] forKey:@"und"];

where files is:

    NSArray *files = @[
                       @{
                           @"fid": fid,
                           },
                       @{
                           @"fid": @"77",
                           },
                       ];

where those fids already exist in my drupal database.

Another problem is when i create node with nodeSave and no images attached.
An upload and attach to that node doesn't work at all.

Can you help me to solve this issue?

@kylebrowning
Collaborator

This is a bug in services not DIOS.
https://www.drupal.org/node/1433254

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment