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

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.

  • Levenshtein Distance Algorithm better than O(n*m)?
  • Load image/logo in existing HTML input field - UIWebView
  • kCAFilterNearest maginifcation filter (UIImageView)
  • What is the best way to connect Realm and SwiftBond
  • iOS: tableView.reloadData() doesn't work in swift
  • Why does UICollectionView log an error when the cells are fullscreen?
  • 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 ?

    Solutions Collect From Internet About “How to upload the Users profile pic and how to fetch that profile pic from another users device?”

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