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 { ROUTES, AUTH_TOKEN } from 'constants/index'; | ||||||
| import UserContext from 'contexts/UserContext'; | import UserContext from 'contexts/UserContext'; | ||||||
| import { GET_ALL_PROFILES, GET_API_URL } from 'graphql/queries'; | import { GET_ALL_PROFILES, GET_API_URL } from 'graphql/queries'; | ||||||
| import { FILE_UPLOAD } from 'graphql/mutations'; |  | ||||||
| import { fetchMoreProfiles } from 'graphql/functions'; | import { fetchMoreProfiles } from 'graphql/functions'; | ||||||
| import { getItem } from 'utils/localStorage'; | import { getItem } from 'utils/localStorage'; | ||||||
|  |  | ||||||
| @@ -133,8 +132,6 @@ const ProfileDetails = () => { | |||||||
|   const [updateProfile] = useMutation(UPDATE_PROFILE); |   const [updateProfile] = useMutation(UPDATE_PROFILE); | ||||||
|   const [deleteProfile] = useMutation(DELETE_PROFILE); |   const [deleteProfile] = useMutation(DELETE_PROFILE); | ||||||
|  |  | ||||||
|   const [fileUpload] = useMutation(FILE_UPLOAD); |  | ||||||
|  |  | ||||||
|   const handleDeleteProfile = () => { |   const handleDeleteProfile = () => { | ||||||
|     deleteProfile({ variables: { id } }) |     deleteProfile({ variables: { id } }) | ||||||
|       .then(() => { |       .then(() => { | ||||||
| @@ -180,20 +177,45 @@ const ProfileDetails = () => { | |||||||
|       ); |       ); | ||||||
|   }; |   }; | ||||||
|  |  | ||||||
|   const handleFileUpload = (fileName, file) => |   const handleFileUpload = async (fileName, file) => { | ||||||
|     fileUpload({ variables: { fileName, file } }) |     const token = getItem(AUTH_TOKEN); | ||||||
|       .then(() => { |  | ||||||
|         notification.success({ |     if (apiUrl?.getApiUrl) { | ||||||
|           message: 'Success', |       fetch(`${apiUrl?.getApiUrl}filestore/${fileName}`, { | ||||||
|           description: 'File successfully uploaded.', |         method: 'POST', | ||||||
|         }); |         headers: { | ||||||
|  |           Authorization: token ? `Bearer ${token.access_token}` : '', | ||||||
|  |           'Content-Type': 'application/octet-stream', | ||||||
|  |         }, | ||||||
|  |         body: file, | ||||||
|       }) |       }) | ||||||
|       .catch(() => |         .then(response => response.json()) | ||||||
|         notification.error({ |         .then(resp => { | ||||||
|           message: 'Error', |           if (resp?.success) { | ||||||
|           description: 'File could not be uploaded.', |             notification.success({ | ||||||
|  |               message: 'Success', | ||||||
|  |               description: 'File successfully uploaded.', | ||||||
|  |             }); | ||||||
|  |           } 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 handleDownloadFile = async name => { | ||||||
|     const token = getItem(AUTH_TOKEN); |     const token = getItem(AUTH_TOKEN); | ||||||
| @@ -201,10 +223,19 @@ const ProfileDetails = () => { | |||||||
|       return fetch(`${apiUrl?.getApiUrl}filestore/${encodeURIComponent(name)}`, { |       return fetch(`${apiUrl?.getApiUrl}filestore/${encodeURIComponent(name)}`, { | ||||||
|         method: 'GET', |         method: 'GET', | ||||||
|         headers: { |         headers: { | ||||||
|  |           'Content-Type': 'application/octet-stream', | ||||||
|           Authorization: token ? `Bearer ${token.access_token}` : '', |           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(() => { |         .catch(() => { | ||||||
|           notification.error({ |           notification.error({ | ||||||
|             message: 'Error', |             message: 'Error', | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Sean Macfarlane
					Sean Macfarlane