Skip to content

Commit ccb6df7

Browse files
authored
fix: notebook should detect mime type (#9)
1 parent 80ff248 commit ccb6df7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/examples/notebooks/vectorize.ipynb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@
192192
{
193193
"cell_type": "code",
194194
"source": [
195-
"import urllib3, json, os\n",
195+
"import urllib3, json, os, mimetypes\n",
196196
"http = urllib3.PoolManager()\n",
197197
"file_path = \"apple.pdf\"\n",
198+
"content_type, _ = mimetypes.guess_type(file_path)\n",
198199
"\n",
199200
"uploads_api = v.UploadsApi(api)\n",
200201
"\n",
@@ -203,13 +204,13 @@
203204
"upload_response = uploads_api.start_file_upload_to_connector(\n",
204205
" org, source_connector_id, v.StartFileUploadToConnectorRequest(\n",
205206
" name=file_path.split(\"/\")[-1],\n",
206-
" content_type=\"application/pdf\",\n",
207+
" content_type=content_type,\n",
207208
" # add additional metadata that will be stored along with each chunk in the vector database\n",
208209
" metadata=json.dumps(metadata))\n",
209210
")\n",
210211
"\n",
211212
"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",
213214
"if response.status != 200:\n",
214215
" print(\"Upload failed: \", response.data)\n",
215216
"else:\n",
@@ -547,12 +548,10 @@
547548
{
548549
"cell_type": "code",
549550
"source": [
550-
"from pathlib import Path\n",
551551
"import urllib3, os\n",
552552
"\n",
553553
"files_api = v.FilesApi(api)\n",
554554
"\n",
555-
"content_type=\"application/pdf\"\n",
556555
"file_path=\"apple.pdf\"\n",
557556
"\n",
558557
"start_file_upload_response = files_api.start_file_upload(org, start_file_upload_request=v.StartFileUploadRequest(\n",

0 commit comments

Comments
 (0)