Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attach multiple files to node #99

Closed
antoniolore opened this issue Sep 26, 2013 · 1 comment
Closed

Attach multiple files to node #99

antoniolore opened this issue Sep 26, 2013 · 1 comment

Comments

@antoniolore
Copy link

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
Copy link
Owner

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants