title: Why Browser gets round trip/refreshed after uploading image more than 9 MB in reactjs?
body: <p>I have a ReactJS APP. The logic in the APP needs to make an http post request to nodejs uploading image api,
  capturing the response from api give some errors and sometimes uploads, and then refreshed the browser instantly. My problem is capturing the http response from nodejs api asynchronously and returning it to the image/display list without a browser refresh.</p>
  <p>When I try to upload more than 6MB to 46MB then a browser refresh must be occured.</p>
  <p>--- ImageComponent.js</p>
  <pre><code>function EditImageSlider({ breadcrumb, pageName, setLoader, showToast }) {
  
  
  const history = useHistory();   
  const list = useSelector((state) =&gt; state.imagecrop.list);
  const detail = useSelector((state) =&gt; state.imagecrop.detail);
  const row = useSelector((state) =&gt; state.imagecrop.row);
  const imageCropWidth = useSelector((state) =&gt; state.imagecrop.imageCropWidth);
  const imageCropHeight = useSelector((state) =&gt; state.imagecrop.imageCropHeight);
  const croppedImage = useSelector((state) =&gt; state.imagecrop.croppedImage);
  const Image = useSelector((state) =&gt; state.imagecrop.Image);
  const ImageName = useSelector((state) =&gt; state.imagecrop.ImageName);
  const errorMessage = useSelector((state) =&gt; state.imagecrop.errorMessage);
  const umodalShow = useSelector((state) =&gt; state.imagecrop.umodalShow);
  const cropSize = useSelector((state) =&gt; state.imagecrop.cropSize);
  const IsDisabled = useSelector((state) =&gt; state.imagecrop.IsDisabled);
  const [currentImage, setCurrentImage] = useState(&quot;&quot;);  
  const [croppedAreaPixels, setCroppedAreaPixels] = useState(null); 
      const singlefileSelectedHandler = async (e) =&gt; {
          //debugger;
          e.preventDefault();
          //setIsDisabled(true);
          dispatch(imageCropActions.setIsDisabled({ IsDisabled: true }));
          content = &quot;&quot;;
  
          if (!e.target.files || e.target.files.length &lt;= 0) {
              return -1;
          }
  
          if (detail &amp;&amp; detail.Content) {
              content = detail.Content;
          }
          //let imageList = &quot;&quot;;
          const selectedImage = e.target.files[0];
          let imageSizeInMBs = selectedImage.size ? selectedImage.size / 1024 / 1024 : 0;
          if (selectedImage &amp;&amp; imageSizeInMBs &gt; 50) {
              dispatch(imageCropActions.setIsDisabled({ IsDisabled: false }));
              showToast(&quot;Information!&quot;, &quot;Image size can't be greater than 8MB.&quot;);
             return -1;
          }
          const filename =
              selectedImage &amp;&amp; selectedImage.name
                  ? new Date().valueOf() +
                    &quot;_&quot; +
                    selectedImage.name.replace(/\\/g, &quot;&quot;).replace(/ /g, &quot;&quot;).replace(/'/g, &quot;&quot;).replace(/&quot;/g, &quot;&quot;).replace(/`/g, &quot;&quot;)
                  : &quot;&quot;;
          imageCropHeight ? parseInt(imageCropHeight) : 0 });      
        
          setCurrentImage(selectedImage);
          const localconvertedImage = URL.createObjectURL(selectedImage);        
          dispatch(
              imageCropActions.setImageAttributes({
                  Image: localconvertedImage,
                  ImageName: filename,
                  croppedImage: localconvertedImage,
                  show: true,
                  width: imageCropWidth ? parseInt(imageCropWidth) : 0,
                  height: imageCropHeight ? parseInt(imageCropHeight) : 0,
                  IsDisabled: false,
              })
          );       
      };
  
  const onSaveImage = async (event) =&gt; {
          //debugger;
          event.preventDefault();
          if (validate() &lt; 0) {
              return -1;
          }
          try {
              let filename = ImageName ? ImageName : &quot;&quot;;
              if (currentImage) {               
                  //debugger;
                  dispatch(sendImageData(filename, croppedAreaPixels, currentImage));
              }
          } catch (err) {
              debugger;
              dispatch(imageCropActions.setImage(&quot;&quot;));
              dispatch(imageCropActions.setImageName(&quot;&quot;));                     
              console.log(err);
          }
      }; 
  
      return (
              &lt;&gt;
                  &lt;label className=&quot;form-label&quot; htmlFor=&quot;customFile&quot;&gt;
                      Upload image
                  &lt;/label&gt;
                  &lt;div className=&quot;custom-file&quot;&gt;
                      &lt;input type=&quot;file&quot; className=&quot;custom-file-input&quot; id=&quot;customFile&quot; onChange={singlefileSelectedHandler} /&gt;
                      &lt;label className=&quot;custom-file-label&quot; htmlFor=&quot;customFile&quot;&gt;
                          Choose file
                      &lt;/label&gt;
                  &lt;/div&gt;
  &lt;div className=&quot;form-row justify-content-end&quot;&gt;
                  &lt;Button className=&quot;btn btn-secondary&quot; disabled={IsDisabled} onClick={onSaveImage }&gt;
                      Save
                  &lt;/Button&gt;
              &lt;/div&gt;
              &lt;/&gt;
          );
      }
  
  
  --- ImageActions.js 
  export const sendImageData = (filename, croppedAreaPixels, cropImage) =&gt; {
      return async (dispatch) =&gt; {
  const sendRequest = async () =&gt; {
              //debugger;           
              let uploadedImageUrl = &quot;&quot;;
              let uploadedImageName = &quot;&quot;;
              let uploadedServerPath = &quot;&quot;;
              let uploadurl = &quot;&quot;;
              const formData = new FormData();
              formData.append(&quot;coord&quot;, JSON.stringify(croppedAreaPixels));
              formData.append(&quot;image&quot;, cropImage);
              let submitUrl = process.env.REACT_APP_SERVER_DOMAIN + `/uploaddetail`;
              //debugger;
              const responseWebApi = await axios.post(submitUrl, formData, {
                  timeout: 30000,
                  timeoutErrorMessage: &quot;The request timeout has been occured during the Image Upload&quot;,
                  headers: {
                      Accept: &quot;application/json&quot;,
                      &quot;Content-Type&quot;: &quot;multipart/form-data&quot;,
                  },
              });
  
              const jsonRes = responseWebApi ? responseWebApi.data : &quot;&quot;;
              if (jsonRes) {             
                  return {
                      ImageName: jsonRes.imagename,
                      ImageServerPath: jsonRes.serverpath,
                      ImageFullUrl: jsonRes.fullurl,
                      ImageUrl: jsonRes.url,
                  };
              }
          };
          try {
              const returnData = await sendRequest();
              dispatch(imageCropActions.updateCropImage({ newRow: returnData, show: false, IsDisabled: false }));
              debugger;
              return 0;
          } catch (error) {
              debugger;         
          }
  };
  };
  </code></pre>
  <p>The error I get here is Uncaught TypeError:</p>
  <pre><code>Browser Headers: 
  Request URL: http://localhost:8001/uploaddetail
  Request Method: POST
  Status Code: 200 OK
  Remote Address: [::1]:8001
  Referrer Policy: strict-origin-when-cross-origin
  </code></pre>
  <p>Browser Response tab:
  Failed to load response data : No resource is given identifier found.</p>
  <p>After that a browser refresh occurs. Any help is appreciated.</p>
  <p>. I understand why I'm getting the error (because apiRes is out of scope), I just can't figure out how to do it right. Any help much appreciated!</p>
  <pre><code>  -- PAckage.json
      {
          &quot;name&quot;: &quot;admin-panel&quot;,
          &quot;version&quot;: &quot;0.1.0&quot;,
          &quot;private&quot;: true,
          &quot;dependencies&quot;: {    
              &quot;@reduxjs/toolkit&quot;: &quot;^1.7.2&quot;,
              &quot;@testing-library/jest-dom&quot;: &quot;^5.12.0&quot;,
              &quot;@testing-library/react&quot;: &quot;^11.2.7&quot;,
              &quot;@testing-library/user-event&quot;: &quot;^12.8.3&quot;,
              &quot;axios&quot;: &quot;^0.26.0&quot;,
              &quot;bootstrap&quot;: &quot;^4.6.0&quot;,
              &quot;faker&quot;: &quot;^5.5.3&quot;,
              &quot;node-sass&quot;: &quot;^4.14.1&quot;,
              &quot;rangeslider-pure&quot;: &quot;^0.4.11&quot;,
              &quot;react&quot;: &quot;^17.0.2&quot;,
              &quot;react-bootstrap&quot;: &quot;^1.6.1&quot;,
              &quot;react-bootstrap-sweetalert&quot;: &quot;^5.2.0&quot;,
              &quot;react-data-table-component&quot;: &quot;^6.11.7&quot;,
              &quot;react-dom&quot;: &quot;^17.0.2&quot;,
              &quot;react-easy-crop&quot;: &quot;^4.0.0&quot;,
              &quot;react-hook-form&quot;: &quot;^7.12.2&quot;,
              &quot;react-icons&quot;: &quot;^4.2.0&quot;,
              &quot;react-nestable&quot;: &quot;^2.0.0&quot;,
              &quot;react-redux&quot;: &quot;^7.2.6&quot;,
              &quot;react-router-dom&quot;: &quot;^5.2.0&quot;,
              &quot;react-scripts&quot;: &quot;^4.0.3&quot;,
              &quot;styled-components&quot;: &quot;^5.3.0&quot;,
              &quot;web-vitals&quot;: &quot;^1.1.2&quot;,
              &quot;yup&quot;: &quot;^0.32.9&quot;
          },
          &quot;scripts&quot;: {
              &quot;start&quot;: &quot;set PORT=3001 &amp;&amp;react-scripts start&quot;,
              &quot;build&quot;: &quot;react-scripts build&quot;,
              &quot;test&quot;: &quot;react-scripts test&quot;,
              &quot;eject&quot;: &quot;react-scripts eject&quot;
          },
          &quot;eslintConfig&quot;: {
              &quot;extends&quot;: [
                  &quot;react-app&quot;,
                  &quot;react-app/jest&quot;
              ]
          },
          &quot;browserslist&quot;: {
              &quot;production&quot;: [
                  &quot;&gt;0.2%&quot;,
                  &quot;not dead&quot;,
                  &quot;not op_mini all&quot;
              ],
              &quot;development&quot;: [
                  &quot;last 1 chrome version&quot;,
                  &quot;last 1 firefox version&quot;,
                  &quot;last 1 safari version&quot;
              ]
          },
         
      }
  </code></pre>
  <p>I have tried to create a full sample code example at
  <a href="https://codesandbox.io/s/vigorous-heisenberg-vbdwo?file=/src/EditImageSlider.js" rel="nofollow noreferrer">https://codesandbox.io/s/vigorous-heisenberg-vbdwo?file=/src/EditImageSlider.js</a></p>
  <p>Is there any restriction in the react for uploading image file size ?</p>
  <p>I found a link and image is not being uploaded there as well.</p>
  <p><a href="https://i.stack.imgur.com/NRJkX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NRJkX.png" alt="enter image description here" /></a></p>
  <p><a href="https://codepen.io/ccnokes/pen/wyBYOd" rel="nofollow noreferrer">https://codepen.io/ccnokes/pen/wyBYOd</a></p>
  <p>I have added more code in the sample code.
  If anyone can see it then please</p>