-
Notifications
You must be signed in to change notification settings - Fork 93
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
nodeAttachFile example for Services 7.x-3.x #46
Comments
I'm trying to attach file to a node and it doesn't work. Is the nodeAttachFile method work ? I'm working on 7.14 drupal version . Thanks in advance |
Does this code help you? [[AppDelegate customStatusBar] showWithStatusMessage:@"Uploading"];
NSData *imgData = UIImageJPEGRepresentation(img, 1.0);
NSMutableDictionary *file = [[NSMutableDictionary alloc] init];
NSString *base64Image = [(NSData *)imgData base64EncodedString];
[file setObject:base64Image forKey:@"file"];
NSString *timestamp = [NSString stringWithFormat:@"%d", (int)[[NSDate date] timeIntervalSince1970]];
NSString *imageTitle = [[articleTitle text] stringByReplacingOccurrencesOfString:@" " withString:@"_"];
NSString *filePath = [NSString stringWithFormat:@"%@%@.jpg",@"public://", 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"];
[self setFileData:file];
[[AppDelegate customStatusBar] hide];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
#warning We should let the user know rather than dumping a log
NSLog(@"Something went wrong: %@", [error localizedDescription]);
}];
[self dismissModalViewControllerAnimated:YES]; |
Thanks but how to link the file with a node on site ??? Best regards, Envoyé de mon iPhone Le 18 juil. 2012 à 23:12, "Kyle Browning" reply@reply.github.com a écrit :
|
I found the solution. |
Hi JC2011, |
Thank you, I did it. |
@loh Care to explain how? |
Well, I eventually figured it out. I'm sure it's wrong, because I don't really know what I'm doing, but it works. Anyway, after uploading the file, grab the fid and start creating a new node like so... NSMutableDictionary *newNodeData = [NSMutableDictionary new]; [newNodeData setValue:fldTitle.text forKey:@"title"]; [newNodeData setValue:@"photo" forKey:@"type"]; [newNodeData setValue:@"und" forKey:@"language"]; These next four lines are where you add the file (in my case, the field is field_photo)... NSMutableDictionary *dict = [NSMutableDictionary dictionary]; [dict setObject:[NSString stringWithFormat:@"%@", fid] forKey:@"fid"]; NSDictionary *fidLangDict = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:dict] forKey:@"und"]; [newNodeData setObject:fidLangDict forKey:@"field_photo"]; Then finish up... [DIOSNode nodeSave:newNodeData success:^(AFHTTPRequestOperation *operation, id responseObject) { //Successful node Creation, etc, etc Suggestions welcome! |
Hi Kyle,
It looks like file_attach is still a work in progress on Services 7.x-3.x: http://drupal.org/node/1484992
I'm wondering if there's a DIOS 2.0 example out with working file attachment.
I am unable to attach files from DIOS at the moment, and I don't know if my issue is my Drupal configuration or DIOS.
The text was updated successfully, but these errors were encountered: