title: Google Drive API - Upload local folder node.js
body: <p>please, I would like to upload local folder with all files and subdirectories to Google Drive (API) with Node.js. </p>
  
  <p>Code uploads only part of the file and not complete file. (i.e. image has 74kB, uploaded file 64kB, part of image is missing)</p>
  
  <pre><code>const simpleUpload = async (filename, path, parent) =&gt; {
  const drive = await getDrive();
  
  var fileMetadata = {
      'name': filename,
  };
  console.log(parent);
  const parentFolder = await searchFiles(parent);
  if (parentFolder.length &gt; 0) {
      fileMetadata.parents = [parentFolder.pop().id]
  }
  
  const fileMimeType = mime.getType(path)
  console.log(fileMimeType)
  
  const media = {
      mimeType: fileMimeType,
      body: fs.createReadStream(path)
  };
  
  drive.files.create({
      resource: fileMetadata,
      media: media,
      fields: 'id'
  }, function (err, file) {
      if (err) {
          // Handle error
          console.error(err);
      } else {
          console.log('File Id: ', file.id);
      }
  });
  </code></pre>
  
  <p>}</p>
  
  <p>And usage:</p>
  
  <pre><code>var generator = fileHelper.walk('archive')
      setTimeout(function () {
          const file = generator.next().value;
          const pathParts = file.split(path.sep)
  
          googleDrive.createFolder(pathParts[1], 'archive')
              .then(() =&gt; {
                  googleDrive.createFolder(pathParts[2], pathParts[1])
                      .then(() =&gt; {
                          googleDrive.simpleUpload(pathParts[3], file, pathParts[2]).then(() =&gt; console.log('File uploaded'))
                      })
              })
      }, 5000)
  </code></pre>
  
  <p>Please, help.</p>