问题描述
在使用Drupal服务和DIOS SDK成功上传照片后,我想为用户设置用户图片(fid)。我使用DIOS SDK(DIOSFile)的fileSave方法上传文件。服务然后返回刚刚上传的用户图片的fid。当我为当前登录的用户设置用户图片字段的fid时,它不会被设置。没有错误,它实际上返回成功,但如果我检查数据库的users表中的图片字段,则没有设置任何内容。我可以更新附加到用户的其他数据,如用户名,电子邮件,密码和其他自定义字段,所以我不认为这是一个权限问题。
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) {
...
}];
这篇文章建议使用文件的fid:
This post suggested to use the "fid" of the file: https://github.com/kylebrowning/drupal-ios-sdk/issues/28
推荐答案
首先,我已经在drupal中创建了一个与userProfile相关的用户(使用PID)。
First of all i have created a user in drupal with a userProfile related (with PID).
我使用这个方法与3个参数:
Than i have used this method with 3 parameters:
nameEntity =要更新的实体drupal的名称;
nameEntity = name of entity drupal to update;
fid =你知道这是什么意思;
fid = you know what this mean;
entityID =要更新的实体的ID;
entityID = id of entity to update;
最后更新实体!
适用于我:
+ (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);
}];
}
这篇关于使用Drupal Services和DIOS SDK在iOS应用程序中设置用户图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!