Upload content to the assistant

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:

  curl -X POST \ 
 -H "Authorization: Bearer $(gcloud auth print-access-token)" \ 
 -H "Content-Type: application/json" \ 
 -H "X-Goog-User-Project: PROJECT_ID 
" \ 
 "https://discoveryengine.googleapis.com/v1alpha/projects/ PROJECT_ID 
/locations/global/collections/default_collection/engines/ APP_ID 
/sessions/ SESSION_ID 
:addContextFile" \ 
 -d '{ 
 "name": "projects/ PROJECT_ID 
/locations/global/collections/default_collection/engines/ APP_ID 
/sessions/ SESSION_ID 
", 
 "fileName": " FILE_NAME 
", 
 "mimeType": " MIME_TYPE 
", 
 "fileContents": " BASE64_ENCODED_FILE 
", 
 }' 
 

Replace the following:

  • PROJECT_ID : the ID of your Google Cloud project.
  • APP_ID : the ID of the app.
  • SESSION_ID : 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 .
  • FILE_NAME : the name of the file.
  • MIME_TYPE : the MIME type of the file.
  • 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==

Example command and response:

  curl -X POST \ 
 -H "Authorization: Bearer $(gcloud auth print-access-token)" \ 
 -H "Content-Type: application/json" \ 
 -H "X-Goog-User-Project: 1234" \ 
 "https://discoveryengine.googleapis.com/v1alpha/projects/1234/locations/global/collections/default_collection/engines/myapp/sessions/16002628354770206943:addContextFile" \ 
 -d '{ 
 "name": "projects/1234/locations/global/collections/default_collection/engines/myapp/sessions/16002628354770206943", 
 "fileName": "Hello World.pdf", 
 "mimeType": "application/pdf", 
 "fileContents": JVBERi0xLjQKJdPr6eEKMSAwIG9iago8PC9UaXRsZSAoSGVsbG8gd29ybGQpCi9Qcm9kdWNlciAoU2tpYS9QREYgbTEzMCBHb29nbGUgRG9jcyBSZW5kZXJlcik+PgplbmRvYmoKMyAwIG9iago8PC..............KMDAwMDAxNDk0NCAwMDAwMCBuIAp0cmFpbGVyCjw8L1NpemUgMTIKL1Jvb3QgNyAwIFIKL0luZm8gMSAwIFI+PgpzdGFydHhyZWYKMTU0NjYKJSVFT0YK", 
 }' 
 
{ "session": "projects/1234/locations/global/collections/default_collection/engines/myapp/sessions/16002628354770206943", "fileId": "11157546467692423460", "tokenCount": "258" }
Design a Mobile Site
View Site in Mobile | Classic
Share by: