# Global persistence.cpp:505 open Can't open file in read mode

**URL:** <https://forum.opencv.org/t/global-persistence-cpp-505-open-cant-open-file-in-read-mode/12581>\
**Category:** Uncategorized\
**Tags:** programming, opencvjs, nodejs\
**Created:** [March 29, 2023, 4:32am UTC](https://forum.opencv.org/t/global-persistence-cpp-505-open-cant-open-file-in-read-mode/12581 "2023-03-29T04:32:28Z")\
**Posts on this page:** 1\
**Page:** 2

<div class="post-metadata">

**Author:** ![fmacdee](https://avatars.discourse-cdn.com/v4/letter/f/46a35a/32.png) [@fmacdee](https://forum.opencv.org/u/fmacdee)\
**Post date:** [March 21, 2024, 2:13pm UTC](https://forum.opencv.org/t/global-persistence-cpp-505-open-cant-open-file-in-read-mode/12581/21 "2024-03-21T14:13:10Z")

</div>

OK, the problem is that you need to get the XML file into the cv filesystem. The answer is in this stackoverflow post:

> <https://stackoverflow.com/questions/67832067/using-javascript-to-load-haarcascasdes-file-always-return-false>

Here is the solution:  
Ok, so you need to make the file accessible to cv by reading it into the opencv file system. To do this, you need to use an XMLHttpRequest() to get the XML file using its URL and then call the cv.CascadeClassifier as follows:

```auto
const xml_model_url = 'https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_default.xml';
const xml_path = "haarcascade_frontalface_default.xml";
let faceCascade = null;

function createFileFromUrl(path, url, callback) {
// path: string to access loaded file trough cv
// url: path of the actual file on your FS
// callback: what to do when file is loaded

  let request = new XMLHttpRequest();
  request.open('GET', url, true);
  request.responseType = 'arraybuffer';
  request.onload = function(ev) {
      request = this;
      if (request.readyState === 4) {
          if (request.status === 200) {
              let data = new Uint8Array(request.response);
              cv.FS_createDataFile('/', path, data, true, false, false);
              callback();
          } else {
              console.error('Failed to load ' + url + ' status: ' + request.status);
          }
      }
  };
  request.send();
}
function createCascade() {
  faceCascade = new cv.CascadeClassifier(xml_path);
}
createFileFromUrl(xml_path, xml_model_url,createCascade);

```

[Previous page](https://forum.opencv.org/t/global-persistence-cpp-505-open-cant-open-file-in-read-mode/12581.md?page=1)
