mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ui.git
				synced 2025-10-31 02:37:54 +00:00 
			
		
		
		
	fixed image upload
This commit is contained in:
		| @@ -7,7 +7,6 @@ import { ProfileDetails as ProfileDetailsPage, Loading } from '@tip-wlan/wlan-cl | ||||
| import { ROUTES, AUTH_TOKEN } from 'constants/index'; | ||||
| import UserContext from 'contexts/UserContext'; | ||||
| import { GET_ALL_PROFILES, GET_API_URL } from 'graphql/queries'; | ||||
| import { FILE_UPLOAD } from 'graphql/mutations'; | ||||
| import { fetchMoreProfiles } from 'graphql/functions'; | ||||
| import { getItem } from 'utils/localStorage'; | ||||
|  | ||||
| @@ -133,8 +132,6 @@ const ProfileDetails = () => { | ||||
|   const [updateProfile] = useMutation(UPDATE_PROFILE); | ||||
|   const [deleteProfile] = useMutation(DELETE_PROFILE); | ||||
|  | ||||
|   const [fileUpload] = useMutation(FILE_UPLOAD); | ||||
|  | ||||
|   const handleDeleteProfile = () => { | ||||
|     deleteProfile({ variables: { id } }) | ||||
|       .then(() => { | ||||
| @@ -180,20 +177,45 @@ const ProfileDetails = () => { | ||||
|       ); | ||||
|   }; | ||||
|  | ||||
|   const handleFileUpload = (fileName, file) => | ||||
|     fileUpload({ variables: { fileName, file } }) | ||||
|       .then(() => { | ||||
|   const handleFileUpload = async (fileName, file) => { | ||||
|     const token = getItem(AUTH_TOKEN); | ||||
|  | ||||
|     if (apiUrl?.getApiUrl) { | ||||
|       fetch(`${apiUrl?.getApiUrl}filestore/${fileName}`, { | ||||
|         method: 'POST', | ||||
|         headers: { | ||||
|           Authorization: token ? `Bearer ${token.access_token}` : '', | ||||
|           'Content-Type': 'application/octet-stream', | ||||
|         }, | ||||
|         body: file, | ||||
|       }) | ||||
|         .then(response => response.json()) | ||||
|         .then(resp => { | ||||
|           if (resp?.success) { | ||||
|             notification.success({ | ||||
|               message: 'Success', | ||||
|               description: 'File successfully uploaded.', | ||||
|             }); | ||||
|       }) | ||||
|       .catch(() => | ||||
|           } else { | ||||
|             notification.error({ | ||||
|               message: 'Error', | ||||
|               description: 'File could not be uploaded.', | ||||
|             }); | ||||
|           } | ||||
|         }) | ||||
|       ); | ||||
|         .catch(() => { | ||||
|           notification.error({ | ||||
|             message: 'Error', | ||||
|             description: 'File could not be uploaded.', | ||||
|           }); | ||||
|         }); | ||||
|     } else { | ||||
|       notification.error({ | ||||
|         message: 'Error', | ||||
|         description: 'File could not be uploaded.', | ||||
|       }); | ||||
|     } | ||||
|   }; | ||||
|  | ||||
|   const handleDownloadFile = async name => { | ||||
|     const token = getItem(AUTH_TOKEN); | ||||
| @@ -201,10 +223,19 @@ const ProfileDetails = () => { | ||||
|       return fetch(`${apiUrl?.getApiUrl}filestore/${encodeURIComponent(name)}`, { | ||||
|         method: 'GET', | ||||
|         headers: { | ||||
|           'Content-Type': 'application/octet-stream', | ||||
|           Authorization: token ? `Bearer ${token.access_token}` : '', | ||||
|         }, | ||||
|       }) | ||||
|         .then(res => res.text()) | ||||
|         .then(response => response.blob()) | ||||
|         .then(blob => { | ||||
|           return new Promise((resolve, reject) => { | ||||
|             const reader = new FileReader(); | ||||
|             reader.onloadend = () => resolve(reader.result); | ||||
|             reader.onerror = reject; | ||||
|             reader.readAsDataURL(blob); | ||||
|           }); | ||||
|         }) | ||||
|         .catch(() => { | ||||
|           notification.error({ | ||||
|             message: 'Error', | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Sean Macfarlane
					Sean Macfarlane