|  | 
| 192 | 192 |   { | 
| 193 | 193 |    "cell_type": "code", | 
| 194 | 194 |    "source": [ | 
| 195 |  | -    "import urllib3, json, os\n", | 
|  | 195 | +    "import urllib3, json, os, mimetypes\n", | 
| 196 | 196 |     "http = urllib3.PoolManager()\n", | 
| 197 | 197 |     "file_path = \"apple.pdf\"\n", | 
|  | 198 | +    "content_type, _ = mimetypes.guess_type(file_path)\n", | 
| 198 | 199 |     "\n", | 
| 199 | 200 |     "uploads_api = v.UploadsApi(api)\n", | 
| 200 | 201 |     "\n", | 
|  | 
| 203 | 204 |     "upload_response = uploads_api.start_file_upload_to_connector(\n", | 
| 204 | 205 |     "        org, source_connector_id, v.StartFileUploadToConnectorRequest(\n", | 
| 205 | 206 |     "            name=file_path.split(\"/\")[-1],\n", | 
| 206 |  | -    "            content_type=\"application/pdf\",\n", | 
|  | 207 | +    "            content_type=content_type,\n", | 
| 207 | 208 |     "            # add additional metadata that will be stored along with each chunk in the vector database\n", | 
| 208 | 209 |     "            metadata=json.dumps(metadata))\n", | 
| 209 | 210 |     ")\n", | 
| 210 | 211 |     "\n", | 
| 211 | 212 |     "with open(file_path, \"rb\") as f:\n", | 
| 212 |  | -    "    response = http.request(\"PUT\", upload_response.upload_url, body=f, headers={\"Content-Type\": \"application/pdf\", \"Content-Length\": str(os.path.getsize(file_path))})\n", | 
|  | 213 | +    "    response = http.request(\"PUT\", upload_response.upload_url, body=f, headers={\"Content-Type\": content_type, \"Content-Length\": str(os.path.getsize(file_path))})\n", | 
| 213 | 214 |     "if response.status != 200:\n", | 
| 214 | 215 |     "    print(\"Upload failed: \", response.data)\n", | 
| 215 | 216 |     "else:\n", | 
|  | 
| 547 | 548 |   { | 
| 548 | 549 |    "cell_type": "code", | 
| 549 | 550 |    "source": [ | 
| 550 |  | -    "from pathlib import Path\n", | 
| 551 | 551 |     "import urllib3, os\n", | 
| 552 | 552 |     "\n", | 
| 553 | 553 |     "files_api = v.FilesApi(api)\n", | 
| 554 | 554 |     "\n", | 
| 555 |  | -    "content_type=\"application/pdf\"\n", | 
| 556 | 555 |     "file_path=\"apple.pdf\"\n", | 
| 557 | 556 |     "\n", | 
| 558 | 557 |     "start_file_upload_response = files_api.start_file_upload(org, start_file_upload_request=v.StartFileUploadRequest(\n", | 
|  | 
0 commit comments