0

I can store file uploadFileIds in an array and send to conversation.jsx component sometimes I received this error:

enter image description here

Sometimes it's working accurately but sometimes it's send a warning

Hera is my both component code:

FileUpload.jsx

const handleUpload = async () => {
        setError(null); // Reset error state
        let newUploadFileId;

        if (selectedFile) {
            try {
                const response = await fetch(UPLOAD_URL, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
                        'Authorization': getAuthHeader(),
                    },
                    body: `size=${selectedFile.size}`,
                    signal: abortController.signal,
                });

                const responseData = await response.json();
                const chunk_size = responseData.chunk_size;

                if (selectedFile.size <= 5 * 1024 * 1024) {
                    newUploadFileId = await uploadFilePart(selectedFile, responseData, accessToken.decrypted_access_token);
                } else {
                    const totalChunks = Math.ceil(selectedFile.size / chunk_size);
                    setTargetPercentage(totalChunks);
                    newUploadFileId = await uploadChunks(selectedFile, responseData, accessToken.decrypted_access_token);
                }

                if (newUploadFileId) {
                    // Delay the state update to avoid the React warning
                        setUploadFileIds(prevIds => {
                            const updatedIds = [...prevIds, newUploadFileId];
                            onUploadComplete(updatedIds);
                            return updatedIds;
                        });
                        setShowUploadingMessage(false);
                        setDynamicFileNo(prevCount => prevCount + 1);
                        setTargetPercentage(100);
                }
            } catch (error) {
                setError(error.message);
            }
        } else {
            console.log("Please select a file");
        }
    };

Conversation.jsx

<FileUpload
      selectedFile={selectedFile}
      isUploading={isUploading}
      onUploadComplete={handleUploadFileIds}
      abortController={abortControllerRef.current}
      onError={handleError} // Pass the handleError function
/>


// Function for get ids  
const handleUploadFileIds = (ids) => {
    console.log(ids);
    if (ids) {
        setUploadFileIds(ids);
        setIsSendButtonDisabled(false); // Re-enable the send button
        setIsUploading(false);
    }
};

How can I fix this issue

2
  • We need to see more code in order to help you, are you able to expand? Commented Jul 19, 2024 at 9:33
  • Any specific part of code you want to see. Because I just want to send array using props. This is my function for getting ids handleUpload and this is component where I want to send it and this is function handleUploadFileIds for extracting id. Thanks Commented Jul 19, 2024 at 12:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.