requests=[{'insertInlineImage':{'location':{'index':1,'tabId':TAB_ID},'uri':'https://fonts.gstatic.com/s/i/productlogos/docs_2020q4/v6/web-64dp/logo_docs_2020q4_color_1x_web_64dp.png','objectSize':{'height':{'magnitude':50,'unit':'PT'},'width':{'magnitude':50,'unit':'PT'}}}}]# Execute the request.body={'requests':requests}response=service.documents().batchUpdate(documentId=document_id,body=body).execute()insert_inline_image_response=response.get('replies')[0].get('insertInlineImage')print('Inserted image with object ID: {0}'.format(insert_inline_image_response.get('objectId')))
The method inserts the image as a new
ParagraphElement
with an
InlineObjectElement
of length 1, where the startIndex is the request's location.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-04 UTC."],[],[],null,["You can insert an image into a document using the\n[`InsertInlineImageRequest`](/workspace/docs/api/reference/rest/v1/documents/request#insertinlineimagerequest)\nmethod. You can optionally use the `objectSize` field to resize the image.\nThe image must be publicly accessible through the URL that you provide in this method. \n\nJava \n\n```java\nList\u003cRequest\u003e requests = new ArrayList\u003c\u003e();\nrequests.add(new Request().setInsertInlineImage(new InsertInlineImageRequest()\n .setUri(\"https://fonts.gstatic.com/s/i/productlogos/docs_2020q4/v6/web-64dp/logo_docs_2020q4_color_1x_web_64dp.png\")\n .setLocation(new Location().setIndex(1).setTabId(TAB_ID))\n .setObjectSize(new Size()\n .setHeight(new Dimension()\n .setMagnitude(50.0)\n .setUnit(\"PT\"))\n .setWidth(new Dimension()\n .setMagnitude(50.0)\n .setUnit(\"PT\")))));\n\nBatchUpdateDocumentRequest body = new BatchUpdateDocumentRequest().setRequests(requests);\nBatchUpdateDocumentResponse response = docsService.documents()\n .batchUpdate(DOCUMENT_ID, body).execute();\n```\n\nPHP \n\n```php\n$requests = array();\n$requests[] = new Google_Service_Docs_Request(array(\n 'insertInlineImage' =\u003e array(\n 'uri' =\u003e 'https://fonts.gstatic.com/s/i/productlogos/docs_2020q4/v6/web-64dp/logo_docs_2020q4_color_1x_web_64dp.png',\n 'location' =\u003e array(\n 'index' =\u003e 1,\n 'tabId' =\u003e TAB_ID,\n ),\n 'objectSize' =\u003e array(\n 'height' =\u003e array(\n 'magnitude' =\u003e 50,\n 'unit' =\u003e 'PT',\n ),\n 'width' =\u003e array(\n 'magnitude' =\u003e 50,\n 'unit' =\u003e 'PT',\n ),\n )\n )\n));\n\n// Execute the requests.\n$batchUpdateRequest = new Google_Service_Docs_BatchUpdateDocumentRequest(array(\n 'requests' =\u003e $requests\n));\n$response =\n $docsService-\u003edocuments-\u003ebatchUpdate(DOCUMENT_ID, $batchUpdateRequest);\n```\n\nPython \n\n```python\nrequests = [{\n 'insertInlineImage': {\n 'location': {\n 'index': 1,\n 'tabId': TAB_ID\n },\n 'uri':\n 'https://fonts.gstatic.com/s/i/productlogos/docs_2020q4/v6/web-64dp/logo_docs_2020q4_color_1x_web_64dp.png',\n 'objectSize': {\n 'height': {\n 'magnitude': 50,\n 'unit': 'PT'\n },\n 'width': {\n 'magnitude': 50,\n 'unit': 'PT'\n }\n }\n }\n}]\n\n# Execute the request.\nbody = {'requests': requests}\nresponse = service.documents().batchUpdate(\n documentId=document_id, body=body).execute()\ninsert_inline_image_response = response.get('replies')[0].get(\n 'insertInlineImage')\nprint('Inserted image with object ID: {0}'.format(\n insert_inline_image_response.get('objectId')))\n```\n\nThe method inserts the image as a new\n[`ParagraphElement`](/workspace/docs/api/reference/rest/v1/documents#paragraphelement)\nwith an\n[`InlineObjectElement`](/workspace/docs/api/reference/rest/v1/documents#InlineObjectElement)\nof length 1, where the `startIndex` is the request's location."]]