Header
User Edit Profile Icon
This icon adds a visual representation of the user and helps in quick identification.
Click the Edit icon on a profile picture to upload a new profile picture
Upload call after selecting the profile picture
Payload:
Preview:
Edit Profile Code Snippet
Code Description
File Selection
Captures the selected files from the input event.
File Type Validation
Checks the file types against a predefined list of valid image types ("image/png", "image/jpeg", "image/jpg").
Filters out any files with invalid types and stores them in the invalidFiles array.
Handling API Response:
File Upload Initialization
Stores the selected files in the filesToUpload property.
Filename Initialization
Resets the filename property.
Single File Handling
If files are selected
Takes the first file from the selected files.
Retrieves and stores its name in the filename property.
File Upload Execution
Invokes the uploadFiles method to handle the actual file upload.
File Upload:
Function Parameter Preparation
Constructs a functionParam object containing the userId retrieved from this.userDetails.id.
File Iteration:
Loops through each file in this.filesToUpload.
FormData Preparation
Creates a FormData object and appends file-related information:
'File': Appends the file itself with the key "file".
'Folder': Specifies the target folder as "public/images".
'makePublic': Sets the visibility of the file as public ("makePublic": "true").
'functionName': Specifies the intended function name as "AddUserImage".
'functionParam': Appends the function parameters as a JSON string.
File Upload API Call
Calls the ProfileFileUpload method from this.DataService with the prepared formData.
Subscribes to the observable returned by the API call.
Handling API Response
In the next block, update this.userProfileImage with the URL of the uploaded picture from the API response.
Error Handling
In the error block, logs and displays any errors that occur during the file upload process.
Completion:
Last updated