如何上传用户个人资料图片以及如何从其他用户设备获取该个人资料图片? [英] How to upload the Users profile pic and how to fetch that profile pic from another users device?

查看:178
本文介绍了如何上传用户个人资料图片以及如何从其他用户设备获取该个人资料图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,让我们说我的应用程序有3个用户。我想为每个用户添加一个图像(配置文件pic目的),以便其他两个使用相同应用程序的用户可以看到此图像。就像whatsapp个人资料照片一样。所以为此我做了以下事情。

I have a requirement,Lets say there are 3-Users for my app. I want to add an image(Profile pic purpose) to each user so that this image can be visible to other two users who are using the same app. Just like whatsapp profile pics. So for this purpose I did the following things.

第1步:以User1身份登录
然后我添加了此代码以上传图像文件。在我使用User1凭据登录后,我在上传文件时将公共属性设置为YES。

Step 1 : Logged in as User1 then I added this code to upload image file. After I logged in with User1 credentials and I made Public property as YES while uploading file.

NSData *imageData = UIImagePNGRepresentation([UIImage imageNamed:@"arrow.png"]);

[QBRequest TUploadFile:imageData fileName:@"arrow.png" contentType:@"image/png" isPublic:YES successBlock:^(QBResponse *response, QBCBlob *blob) {

} statusBlock:^(QBRequest *request, QBRequestStatus *status) {
} errorBlock:^(QBResponse *response) {
}];  

第2步:以User2身份登录

然后我确实喜欢这个我正在获取属于我的应用程序的所有用户。使用

Then I did like this I'm fetching all the users belongs to my app. using

QBGeneralResponsePage *responsePage = [QBGeneralResponsePage responsePageWithCurrentPage:currentPage perPage:perPage];

[QBRequest usersForPage:responsePage successBlock:^(QBResponse *response, QBGeneralResponsePage *page, NSArray *users) {

    weakSelf.allUsers = [users mutablecopy]
    [weakSelf.tableView reloadData];

} errorBlock:^(QBResponse *response) {

}];

第3步:
现在我拥有所有用户所以我正在迭代查找用户blob id。

Step 3 : Now I have all the users so I'm doing iteration to find the users blob id .

    QBUUser *user = (QBUUser *)self.allUsers[indexPath.row];


if (user.blobID != 0) {

    [QBRequest downloadFileWithID:user.blobID successBlock:^(QBResponse *response, NSData *fileData) {

        UIImage *img=[UIImage imageWithData:fileData];
        [cell.imageView setImage:img];

    } statusBlock:^(QBRequest *request, QBRequestStatus *status) {

    } errorBlock:^(QBResponse *response) {

    }];
}

但问题是在这里我没有得到任何带有User1的blobID 用户1的blobID为0 (所有用户blobID为0),但上传成功后,我在登录后使用User1上传文件后获得了blobID。

But the problem is here I'm not getting any blobID with the User1 means blobID of user1 as 0(all users blobID as 0), But while uploading it was success and I got blobID after uploading the file using User1 as logged in.

但当我以user2或User3 登录时,它没有显示与user1关联的任何blobID。我在上传时将公开视为是。
这是正确的做法还是我正在做的任何错误请告诉我?

But when I logged in as user2 or User3 it is not showing any blobID associated with user1. And I made Public as Yes while uploading. Is this correct way of doing or any mistake I'm doing please let me know ?

推荐答案

你应该更新用户的blobID在blob上传后使用QBUpdateUserParameters请求:

You should update user's blobID using request with QBUpdateUserParameters after blob's uploading:

      [QBRequest TUploadFile:imageData fileName:@"arrow.png" contentType:@"image/png" isPublic:YES successBlock:^(QBResponse *response, QBCBlob *blob) {

            QBUpdateUserParameters *userParams = [QBUpdateUserParameters new];
            userParams.blobID = blob.ID;

            [QBRequest updateCurrentUser:userParams successBlock:^(QBResponse * _Nonnull __unused response, QBUUser * _Nullable user) {
            } errorBlock:^(QBResponse * _Nonnull response) {

            }];

        } statusBlock:^(QBRequest *request, QBRequestStatus *status) {

        } errorBlock:^(QBResponse *response) {
        }];

这篇关于如何上传用户个人资料图片以及如何从其他用户设备获取该个人资料图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆