title: Batch convert jpg to Google Docs
body: <p>I have a folder of jpgs in Google Drive that I would like to convert to Google Docs. Now I can select each one manually and in the context menu "Open in Google Docs" This creates a new document with the image at the top of the page and OCR text below. I just want to do this with all my images.</p>
  
  <p>There is a script <a href="https://stackoverflow.com/questions/46822740/batch-convert-google-docs-files-to-microsoft-word">here</a> which converts gdoc to docx which I ought to be able to adapt for my case but I don't seem to be able to get it to work. </p>
  
  <p>Here is my adapted script:</p>
  
  <pre><code>function convertJPGtoGoogleDocs() {
    var srcfolderId = "~~~~~~~~~Sv4qZuPdJgvEq1A~~~~~~~~~"; // &lt;--- Please input folder ID.
    var dstfolderId = srcfolderId; // &lt;--- If you want to change the destination folder, please modify this.
    var files = DriveApp.getFolderById(srcfolderId).getFilesByType(MimeType.JPG);
    while (files.hasNext()) {
      var file = files.next();
      DriveApp.getFolderById(dstfolderId).createFile(
        UrlFetchApp.fetch(
          "https://docs.google.com/document/d/" + file.getId() + "/export?format=gdoc",
          {
            "headers" : {Authorization: 'Bearer ' + ScriptApp.getOAuthToken()},
            "muteHttpExceptions" : true
          }
        ).getBlob().setName(file.getName() + ".docx")
      );
    }
  }
  </code></pre>
  
  <p>Can anyone help? </p>
  
  <p>Thanks. </p>