Repository: deepset-ai/haystack

Issue:
Cant Upload a TXT file with REST API
**Describe the bug**
Cant Upload a TXT file with REST API, Receiving the following error

**Error message**
TyperError : 'NoneType' object does not support item assignment

**Expected behavior**
File gets uploaded to the ElasticSearch server and will return answers when asked a query through API 

**Additional context**
I am using a TXT file with  the /file-upload endpoint 
installed the REST API sever with Docker Compose GPU using the latest master branch code.

**To Reproduce**
Clone the Haystack repo
Run the docker GPU compose file. 
Use the curl command inside the GPU Machine to upload the file stored in the same machine with REST API Endpoint. 

**FAQ Check**
- [x] Have you had a look at [our new FAQ page](https://haystack.deepset.ai/overview/faq)?

**System:**
 - Hosting : AWS EC2 GPU instance (g3s.xlarge)
 - OS: Deep Learning Base AMI (Ubuntu 18.04) Version 44.0
 - GPU/CPU: GPU
 - Haystack version (commit or version number): db4d6f4
 - DocumentStore: ElasticSearch 
 - Reader: default (FARM)
 - Retriever: default (DPR)
![file-upload error](https://user-images.githubusercontent.com/93700661/153849332-3e23dd64-e62d-4184-8702-d89ef02d91a9.png)




Discussion:
Hello @rubanrajdavidwl, thank you for this bug report! It seems like a bug on our end. I'll open a PR and submit the bugfix there shortly.

Resolving patch:
diff --git a/rest_api/controller/file_upload.py b/rest_api/controller/file_upload.py
--- a/rest_api/controller/file_upload.py
+++ b/rest_api/controller/file_upload.py
@@ -91,7 +91,10 @@ def upload_file(
 
     file_paths: list = []
     file_metas: list = []
-    meta_form = json.loads(meta)  # type: ignore
+
+    meta_form = json.loads(meta) or {}  # type: ignore
+    if not isinstance(meta_form, dict):
+        raise HTTPException(status_code=500, detail=f"The meta field must be a dict or None, not {type(meta_form)}")
 
     for file in files:
         try:


Test patch:
diff --git a/rest_api/test/test_rest_api.py b/rest_api/test/test_rest_api.py
--- a/rest_api/test/test_rest_api.py
+++ b/rest_api/test/test_rest_api.py
@@ -152,6 +152,9 @@ def test_delete_documents():
 
 
 def test_file_upload(client: TestClient):
+    response = client.post(url="/documents/get_by_filters", data='{"filters": {}}')
+    assert len(response.json()) == 0
+
     file_to_upload = {"files": (Path(__file__).parent / "samples" / "pdf" / "sample_pdf_1.pdf").open("rb")}
     response = client.post(
         url="/file-upload",
@@ -160,6 +163,41 @@ def test_file_upload(client: TestClient):
     )
     assert 200 == response.status_code
 
+    response = client.post(url="/documents/get_by_filters", data='{"filters": {}}')
+    assert len(response.json()) > 0
+
+
+def test_file_upload_with_no_meta(client: TestClient):
+    response = client.post(url="/documents/get_by_filters", data='{"filters": {}}')
+    assert len(response.json()) == 0
+
+    file_to_upload = {"files": (Path(__file__).parent / "samples" / "pdf" / "sample_pdf_1.pdf").open("rb")}
+    response = client.post(
+        url="/file-upload",
+        files=file_to_upload,
+        data={"meta": ""},
+    )
+    assert 200 == response.status_code
+
+    response = client.post(url="/documents/get_by_filters", data='{"filters": {}}')
+    assert len(response.json()) > 0
+
+
+def test_file_upload_with_wrong_meta(client: TestClient):
+    response = client.post(url="/documents/get_by_filters", data='{"filters": {}}')
+    assert len(response.json()) == 0
+
+    file_to_upload = {"files": (Path(__file__).parent / "samples" / "pdf" / "sample_pdf_1.pdf").open("rb")}
+    response = client.post(
+        url="/file-upload",
+        files=file_to_upload,
+        data={"meta": "1"},
+    )
+    assert 500 == response.status_code
+
+    response = client.post(url="/documents/get_by_filters", data='{"filters": {}}')
+    assert len(response.json()) == 0
+
 
 def test_query_with_no_filter(populated_client: TestClient):
     query_with_no_filter_value = {"query": "Who made the PDF specification?"}