MCPcopy Index your code
hub / github.com/OpenSignLabs/OpenSign / handleFileUpload

Function handleFileUpload

apps/OpenSign/src/pages/UserProfile.jsx:176–210  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

174 };
175
176 const handleFileUpload = async (file) => {
177 const size = file.size;
178 const pdfFile = file;
179 const fileName = file.name;
180 const name = sanitizeFileName(fileName);
181 const parseFile = new Parse.File(name, pdfFile);
182
183 try {
184 const response = await parseFile.save({
185 progress: (progressValue, loaded, total) => {
186 if (progressValue !== null) {
187 const percentCompleted = Math.round((loaded * 100) / total);
188 // console.log("percentCompleted ", percentCompleted);
189 setpercentage(percentCompleted);
190 }
191 }
192 });
193 // // The response object will contain information about the uploaded file
194 // console.log("File uploaded:", response);
195
196 if (response?.url()) {
197 const fileRes = await getSecureUrl(response?.url());
198 if (fileRes?.url) {
199 setImage(fileRes?.url);
200 setpercentage(0);
201 const tenantId = localStorage.getItem("TenantId");
202 const userId = extendUser?.[0]?.UserId?.objectId;
203 SaveFileSize(size, fileRes?.url, tenantId, userId);
204 return fileRes?.url;
205 }
206 }
207 } catch (error) {
208 console.error("Error uploading file:", error);
209 }
210 };
211 if (
212 localStorage.getItem("accesstoken") === null &&
213 localStorage.getItem("pageType") === null

Callers 1

fileUploadFunction · 0.70

Calls 3

sanitizeFileNameFunction · 0.90
getSecureUrlFunction · 0.90
SaveFileSizeFunction · 0.90

Tested by

no test coverage detected