How to upload the Users profile pic and how to fetch that profile pic from another users device?

主宰稳场 提交于 2019-11-27 08:16:35

问题


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.

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) {
}];  

Step 2 : Logged in as 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) {

}];

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) {

    }];
}

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.

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 ?


回答1:


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) {
        }];


来源:https://stackoverflow.com/questions/37043763/how-to-upload-the-users-profile-pic-and-how-to-fetch-that-profile-pic-from-anoth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!