The file URL is not a permanent address, so do not save the uploaded file URL in kvstore or local storage for reuse.
❌ Incorrect example
// Example of saving the uploaded file URL in local storage for reuseconstApp= () => {const [profileUrl,setProfileUrl] =useState(null);consthandleUpload=async (e) => {constfile=e.target.files[0];awaiteliceContents.filestore.post('profile', file);const { url } =awaiteliceContents.filestore.get('profile');localStorage.setItem('profileUrl', url);setProfileUrl(url); };useEffect(() => {// ⚠️ If the URL stored in local storage has expired, the image will not be displayed.// Therefore, do not save the uploaded file URL in local storage for reuse.conststoreProfileUrl=localStorage.getItem('profileUrl');setProfileUrl(storeProfileUrl); }, []);return ( <div> {profileUrl && <img src={profileUrl} alt="profile"/>}<input type="file" onChange={handleUpload} /></div> );};
✅ Correct example
// Example of using the file URL uploaded through filestoreconstApp= () => {const [profileUrl,setProfileUrl] =useState(null);consthandleUpload=async (e) => {constfile=e.target.files[0];awaiteliceContents.filestore.post('profile', file);const { url } =awaiteliceContents.filestore.get('profile');setProfileUrl(url); };useEffect(() => {constgetProfileUrl=async () => {// ✅ Use a valid file URL retrieved through filestore.constprofile=awaiteliceContents.filestore.get('profile');if (profile) {setProfileUrl(profile.url); } };getProfileUrl(); }, []);return ( <div> {profileUrl && <img src={profileUrl} alt="profile"/>}<input type="file" onChange={handleUpload} /></div> );};
Methods
post (Upload file)
⚠️ The file size limit is 50MB. Therefore, files larger than 50MB cannot be uploaded.
You can use this method to upload files to the Elice file service.
You can use this method to retrieve files uploaded to the Elice file service. The response includes file metadata such as name, mime, size, and url. You can use the url to access image, video, audio, and other types of files.