Using Drupal Services and DIOS SDK for setting use

2019-09-19 06:20发布

I'm trying to set a user picture (fid) for a user after successfully uploading a photo using Drupal services and DIOS SDK. I upload the file using the "fileSave" method of DIOS SDK (DIOSFile). Services then returns an "fid" for the user picture that was just uploaded. When I try to set the fid for the user picture field for the user who is currently logged in, it doesn't get set. There is no error, it actually returns successfully, but if I check on the "picture" field in the users table of the database, nothing is set. I can update other data that is attached to a user such as username, email, password and other custom fields so I don't think it's a permission issue.

I've tried the following code and many variations of it, but nothing seems to updated the "picture" field.

    _userUpdateParams = [NSMutableDictionary new];
    NSString *fid = @"22"; //For demonstration purposes, I'm hard-coding an fid value.

    if (username)
        [_userUpdateParams setValue:username forKey:@"name"];

    if (password)
        [_userUpdateParams setValue:password forKey:@"current_pass"];

    if (newPassword)
        [_userUpdateParams setValue:newPassword forKey:@"pass"];

    if (email)
        [_userUpdateParams setValue:email forKey:@"mail"];

    if (fid)
        [_userUpdateParams setValue:fid forKey:@"picture"];

    if (uid)
        [_userUpdateParams setValue:uid forKey:@"uid"];


    [DIOSUser userUpdate:_userUpdateParams
                   success:^(AFHTTPRequestOperation *operation, id responseObject) {
                       ...
                   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                       ...
                   }];

This post suggested to use the "fid" of the file: https://github.com/kylebrowning/drupal-ios-sdk/issues/28

1条回答
放荡不羁爱自由
2楼-- · 2019-09-19 06:55

First of all i have created a user in drupal with a userProfile related (with PID).

Than i have used this method with 3 parameters:

nameEntity = name of entity drupal to update;

fid = you know what this mean;

entityID = id of entity to update;

finally update the entity!

works for me:

+ (void)updateEntityUserProfileWithName:(NSString*)nameEntity 
                                   andImageFid:(NSString*)fid 
                                      eid:(NSString*)entityID
      success:(void (^)(AFHTTPRequestOperation *operation, id       responseObject))success
      failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure{

ToPartyUserProfile *user=[ToPartyUserProfile sharedManager];
NSMutableDictionary* entityData = [NSMutableDictionary new];
[entityData setObject:entityID forKey:@"pid"];
[entityData setObject:@"main" forKey:@"type"];
[entityData setObject:@{@"und": @[@{@"value": [user nickname]}]} forKey:@"field_nickname"];
[entityData setObject:@{@"und": @[@{@"value": [user gender]}]} forKey:@"field_sex"];
[entityData setObject:@{@"und": @[@{@"value": [user nationality]}]} forKey:@"field_nationality"];
[entityData setObject:@{@"und": @[@{@"fid": fid}]} forKey:@"field_photo"];

[DIOSEntity entityUpdate:entityData
                    name:nameEntity
                     eid:entityID
                 success:^(AFHTTPRequestOperation *op, id response) {
                     success(op,response);
                 }
                 failure:^(AFHTTPRequestOperation *op, NSError *err) {
                     failure(op,err);
                 }];
}
查看更多
登录 后发表回答