title: Firebase Upload Image to Storage During User Registration
body: <p>I'm new to Firebase, and I have been following their documentation <a href="https://firebase.google.com/docs/storage/ios/upload-files" rel="nofollow">here</a>.
  However, nothing I have tried seems to work.</p>
  
  <p>What I am trying to do:</p>
  
  <p>1) Register a user <strong>-Works</strong></p>
  
  <p>2) Have the user choose a profile picture during the registration process <strong>-Doesn't work.</strong></p>
  
  <p>The code:</p>
  
  <pre><code>- (void) registerNewUser:(FIRUser *)user
  
  {
      FIRUser *currentUser = [FIRAuth auth].currentUser;
      NSString *email = emailAddressTxtField.text;
      NSString *password = passwordTxtField.text;
      NSString *username = usernameTxtField.text;
      [[FIRAuth auth]
       createUserWithEmail:email
       password:password
       completion:^(FIRUser *_Nullable user,
                    NSError *_Nullable error)
       {
           if (error)
           {
               NSLog(@"%@", error.localizedDescription);
               return;
           }
           else
           {
               ////ASSIGN NEW USER THEIR NAME////
               self.databaseRef = [[FIRDatabase database] reference];
               [[[databaseRef child:@"users"] child:user.uid]
                setValue:@{@"name": username}];
           }
       }];
      ////ESTABLISHED A USER, SO LET'S ASSIGN THEIR PIC TO THEM////
      if (profilePicImageView.image)
      {
          FIRStorageReference *profilePicRef = [[storageRef child:@"images/profilePicture.jpg"] child:currentUser.uid];
          FIRStorageMetadata *metadata = [[FIRStorageMetadata alloc] init];
          metadata.contentType = @"image/jpeg";
          NSData *imageData = UIImageJPEGRepresentation(self.profilePicImageView.image, 0.8);
          NSLog(@"metadata from image: %@", metadata);
  
          [profilePicRef putData:imageData metadata:metadata completion:^(FIRStorageMetadata *metadata, NSError *error)
           {
               if (error != nil)
               {
                   NSString *profileImageURL = metadata.downloadURL.absoluteString;
                   NSLog(@"Profile Image URL from image: %@", profileImageURL);
                   [ProgressHUD showSuccess:[NSString stringWithFormat:@"%@ Successfully Registered!!", username]];
                   [self.segmentedLoginRegister setSelectedSegmentIndex:0];
                   [self checkSegmentedControl];
                   [ProgressHUD showSuccess:[NSString stringWithFormat:@"Welcome %@!", username]];
               }
               else
               {
                   NSLog(@"Failed to Register User with profile image");
               }
           }];
      }
  }
  </code></pre>
  
  <p><strong>Additional Information:</strong>  </p>
  
  <p>Photos are coming only from the camera roll of the user's device
  Debug area prints: </p>
  
  <blockquote>
    <p>[Generic] Creating an image format with an unknown type is an error</p>
  </blockquote>