Stay organized with collections
Save and categorize content based on your preferences.
You can upload files to the assistant using the API. These files are available
when you
chat with the assistant.
For information about uploading files within the assistant, see
Upload and chat about files.
To upload content to the assistant using the API, run the following curl
command:
BASE64_ENCODED_FILE: the base64 representation
(ASCII string) of your data. This string should look similar to the
following string: /9j/4QAYRXhpZgAA...9tAVx/zDQDlGxn//2Q==
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[],[],null,["# Upload content to the assistant\n\nYou can upload files to the assistant using the API. These files are available\nwhen you\n[chat with the assistant](/agentspace/docs/assistant-chat).\nFor information about uploading files within the assistant, see\n[Upload and chat about files](/agentspace/docs/assistant-chat#upload_and_chat_about_files).\n\nTo upload content to the assistant using the API, run the following curl\ncommand: \n\n curl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json\" \\\n -H \"X-Goog-User-Project: \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\" \\\n \"https://discoveryengine.googleapis.com/v1alpha/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/collections/default_collection/engines/\u003cvar translate=\"no\"\u003eAPP_ID\u003c/var\u003e/sessions/\u003cvar translate=\"no\"\u003eSESSION_ID\u003c/var\u003e:addContextFile\" \\\n -d '{\n \"name\": \"projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/collections/default_collection/engines/\u003cvar translate=\"no\"\u003eAPP_ID\u003c/var\u003e/sessions/\u003cvar translate=\"no\"\u003eSESSION_ID\u003c/var\u003e\",\n \"fileName\": \"\u003cvar translate=\"no\"\u003eFILE_NAME\u003c/var\u003e\",\n \"mimeType\": \"\u003cvar translate=\"no\"\u003eMIME_TYPE\u003c/var\u003e\",\n \"fileContents\": \"\u003cvar translate=\"no\"\u003eBASE64_ENCODED_FILE\u003c/var\u003e\",\n }'\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your Google Cloud project.\n- \u003cvar translate=\"no\"\u003eAPP_ID\u003c/var\u003e: the ID of the app.\n- \u003cvar translate=\"no\"\u003eSESSION_ID\u003c/var\u003e: the ID of the session. You can obtain this ID from the response of creating a session, as shown in [Store session information and get responses](/agentspace/docs/answer#store-session).\n- \u003cvar translate=\"no\"\u003eFILE_NAME\u003c/var\u003e: the name of the file.\n- \u003cvar translate=\"no\"\u003eMIME_TYPE\u003c/var\u003e: the MIME type of the file.\n- \u003cvar translate=\"no\"\u003eBASE64_ENCODED_FILE\u003c/var\u003e: the base64 representation (ASCII string) of your data. This string should look similar to the following string: `/9j/4QAYRXhpZgAA...9tAVx/zDQDlGxn//2Q==`\n\nExample command and response: \n\n curl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json\" \\\n -H \"X-Goog-User-Project: 1234\" \\\n \"https://discoveryengine.googleapis.com/v1alpha/projects/1234/locations/global/collections/default_collection/engines/myapp/sessions/16002628354770206943:addContextFile\" \\\n -d '{\n \"name\": \"projects/1234/locations/global/collections/default_collection/engines/myapp/sessions/16002628354770206943\",\n \"fileName\": \"Hello World.pdf\",\n \"mimeType\": \"application/pdf\",\n \"fileContents\": JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9UaXRsZSAoSGVsbG8gd29ybGQpCi9Qcm9kdWNlciAoU2tpYS9QREYgbTEzMCBHb29nbGUgRG9jcyBSZW5kZXJlcik+PgplbmRvYmoKMyAwIG9iago8PC..............KMDAwMDAxNDk0NCAwMDAwMCBuIAp0cmFpbGVyCjw8L1NpemUgMTIKL1Jvb3QgNyAwIFIKL0luZm8gMSAwIFI+PgpzdGFydHhyZWYKMTU0NjYKJSVFT0YK\",\n }'\n ------------------\n {\n \"session\": \"projects/1234/locations/global/collections/default_collection/engines/myapp/sessions/16002628354770206943\",\n \"fileId\": \"11157546467692423460\",\n \"tokenCount\": \"258\"\n }"]]