title: How save instance of File in Node.js/Strapi
body: <p>I need to save file recieved from frontend/postman. For example .txt file:
  <a href="https://i.stack.imgur.com/th853.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/th853.png" alt="enter image description here" /></a></p>
  <p>After that, on backend, I get the file like this:</p>
  <pre><code>const { body, files } = ctx.request;
  </code></pre>
  <p>&quot;ctx&quot; it is object refers to Strapi API.
  This file looks like</p>
  <pre><code>console.log(files.client)
  </code></pre>
  <p>It is instance of File:</p>
  <pre><code>File {
    _events: [Object: null prototype] {},
    _eventsCount: 0,
    _maxListeners: undefined,
    size: 7,
    path: 'C:\\Users\\vvv\\AppData\\Local\\Temp\\upload_552c6e1cb7710c6c490533566b7be1d1',
    name: '111.txt',
    type: 'text/plain',
    hash: null,
    lastModifiedDate: 2022-04-20T06:41:53.462Z,
    _writeStream: WriteStream {
      fd: null,
      path: 'C:\\Users\\vvv\\AppData\\Local\\Temp\\upload_552c6e1cb7710c6c490533566b7be1d1',
      flags: 'w',
      mode: 438,
      start: undefined,
      pos: undefined,
      bytesWritten: 7,
      closed: true,
      _writableState: WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: true,
        ended: true,
        finished: true,
        destroyed: true,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: false,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        afterWriteTickInfo: null,
        buffered: [],
        bufferedIndex: 0,
        allBuffers: true,
        allNoop: true,
        pendingcb: 0,
        constructed: true,
        prefinished: true,
        errorEmitted: false,
        emitClose: true,
        autoDestroy: true,
        errored: null,
        closed: true,
        closeEmitted: true,
        [Symbol(kOnFinished)]: []
      },
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      [Symbol(kFs)]: {
        appendFile: [Function: appendFile],
        appendFileSync: [Function: appendFileSync],
        access: [Function: access],
        accessSync: [Function: accessSync],
        chown: [Function: chown],
        chownSync: [Function: chownSync],
        chmod: [Function: chmod],
        chmodSync: [Function: chmodSync],
        close: [Function: close],
        closeSync: [Function: closeSync],
        copyFile: [Function: copyFile],
        copyFileSync: [Function: copyFileSync],
        cp: [Function: cp],
        cpSync: [Function: cpSync],
        createReadStream: [Function: createReadStream],
        createWriteStream: [Function: createWriteStream],
        exists: [Function: exists],
        existsSync: [Function: existsSync],
        fchown: [Function: fchown],
        fchownSync: [Function: fchownSync],
        fchmod: [Function: fchmod],
        fchmodSync: [Function: fchmodSync],
        fdatasync: [Function: fdatasync],
        fdatasyncSync: [Function: fdatasyncSync],
        fstat: [Function: fstat],
        fstatSync: [Function: fstatSync],
        fsync: [Function: fsync],
        fsyncSync: [Function: fsyncSync],
        ftruncate: [Function: ftruncate],
        ftruncateSync: [Function: ftruncateSync],
        futimes: [Function: futimes],
        futimesSync: [Function: futimesSync],
        lchown: [Function: lchown],
        lchownSync: [Function: lchownSync],
        lchmod: undefined,
        lchmodSync: undefined,
        link: [Function: link],
        linkSync: [Function: linkSync],
        lstat: [Function: lstat],
        lstatSync: [Function: lstatSync],
        lutimes: [Function: lutimes],
        lutimesSync: [Function: lutimesSync],
        mkdir: [Function: mkdir],
        mkdirSync: [Function: mkdirSync],
        mkdtemp: [Function: mkdtemp],
        mkdtempSync: [Function: mkdtempSync],
        open: [Function: open],
        openSync: [Function: openSync],
        opendir: [Function: opendir],
        opendirSync: [Function: opendirSync],
        readdir: [Function: readdir],
        readdirSync: [Function: readdirSync],
        read: [Function: read],
        readSync: [Function: readSync],
        readv: [Function: readv],
        readvSync: [Function: readvSync],
        readFile: [Function: readFile],
        readFileSync: [Function: readFileSync],
        readlink: [Function: readlink],
        readlinkSync: [Function: readlinkSync],
        realpath: [Function],
        realpathSync: [Function],
        rename: [Function: rename],
        renameSync: [Function: renameSync],
        rm: [Function: rm],
        rmSync: [Function: rmSync],
        rmdir: [Function: rmdir],
        rmdirSync: [Function: rmdirSync],
        stat: [Function: stat],
        statSync: [Function: statSync],
        symlink: [Function: symlink],
        symlinkSync: [Function: symlinkSync],
        truncate: [Function: truncate],
        truncateSync: [Function: truncateSync],
        unwatchFile: [Function: unwatchFile],
        unlink: [Function: unlink],
        unlinkSync: [Function: unlinkSync],
        utimes: [Function: utimes],
        utimesSync: [Function: utimesSync],
        watch: [Function: watch],
        watchFile: [Function: watchFile],
        writeFile: [Function: writeFile],
        writeFileSync: [Function: writeFileSync],
        write: [Function: write],
        writeSync: [Function: writeSync],
        writev: [Function: writev],
        writevSync: [Function: writevSync],
        Dir: [class Dir],
        Dirent: [class Dirent],
        Stats: [Function: Stats],
        ReadStream: [Getter/Setter],
        WriteStream: [Getter/Setter],
        FileReadStream: [Getter/Setter],
        FileWriteStream: [Getter/Setter],
        _toUnixTimestamp: [Function: toUnixTimestamp],
        F_OK: 0,
        R_OK: 4,
        W_OK: 2,
        X_OK: 1,
        constants: [Object: null prototype],
        promises: [Getter]
      },
      [Symbol(kIsPerformingIO)]: false,
      [Symbol(kCapture)]: false
    },
    [Symbol(kCapture)]: false
  }
  </code></pre>
  <p>How save it on server? I was trying to do it via <code>fs.writeFile</code> and <code>fs.createWriteStream</code>:</p>
  <pre><code>      fs.writeFile(filePath, files.client, function(err) {
          if(err) {
            return console.log(err);
          }
          console.log(&quot;The file was saved!&quot;);
        });
  </code></pre>
  <p>OR</p>
  <pre><code>      let writeableStream = fs.createWriteStream(filePath);
        writeableStream.write(files.client);
  </code></pre>
  <p>But everytime I got an error:</p>
  <pre><code>TypeError [ERR_INVALID_ARG_TYPE]: The &quot;data&quot; argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of File
  </code></pre>
  <pre><code>TypeError [ERR_INVALID_ARG_TYPE]: The &quot;chunk&quot; argument must be of type string or an instance of Buffer or Uint8Array. Received an instance of File
  </code></pre>