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 the call after selecting the profile picture.
Payload:
Preview:
Edit Profile Code Snippet
Below is the Header code snippet.
Code Description
This function, handleFileChange, is designed to handle a file change event, associated with a file input in a form. Here's a breakdown of its functionality:
Retrieve User ID
Retrieves the user ID from localStorage using localStorage.getItem('userDetails').
Parses the user details as JSON and extracts the user ID.
Function Parameters
Creates a functionParam object containing the user ID as a parameter.
Form Data Preparation
Creates a new FormData object (formData).
Appends various parameters to the FormData:
'file': The actual file from the file input.
'folder': Specifies the folder for storing the uploaded file ('public/images' in this case).
'make public': A boolean indicating whether the file should be made public (set to true).
'functionName': Specifies the name of the function to be called on the server ('AddUserImage').
'functionParam': The function parameters, including the user ID.
File Upload Using Fetch API
Makes an asynchronous call to the 'https://api.eng-dev-1.trilloapps.com/foldersvc/cloudstorage/upload' endpoint using the Fetch API.
Configures the request with method 'POST', necessary headers, and the prepared FormData.
Uses the 'Authorization' header to include the user's access token from localStorage.
Response Handling
Parses the response as JSON.
If the response indicates success:
Logs a success message to the console.
Updates the user profile with the new picture URL.
Displays a success toast notification.
Error Handling
Catches any errors that occur during the file upload process.
Logs an error message to the console.
Last updated