[GH-ISSUE #2947] [BUG]: Unable to Upload File via /api/v1/document/upload #1880

Closed
opened 2026-02-22 18:26:58 -05:00 by yindo · 5 comments
Owner

Originally created by @LukiaLiang on GitHub (Jan 7, 2025).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2947

How are you running AnythingLLM?

AnythingLLM desktop app

What happened?

I am testing to upload a file using /api/v1/document/upload. Below is the code I am using:

import requests
import os

api_url = "http://localhost:3001/api/v1/document/upload"
headers = {
    "Authorization": "[My API Key]",
    "accept": "application/json"
}

pdf_filename = "temp.pdf"

with open(pdf_filename, "rb") as f:
    files = {"file": (pdf_filename, f, "application/pdf")}
    print(f"Sending files: {pdf_filename}")
    response = requests.post(api_url, headers=headers, files=files)

    if response.status_code == 200:
        print("PDF successfully uploaded to the API.")
    else:
        print(f"Failed. Status code: {response.status_code}, Response: {response.text}")

The file temp.pdf exists in the same directory as the script.

However, the program is returning the following error:

Sending files: temp.pdf
Failed. Status code: 500, Response: {"success":false,"error":"Invalid file upload. ENOENT: no such file or directory, open 'C:\\Users\\[My Username]\\AppData\\Roaming\\collector\\hotdir\\temp.pdf'"}

In fact, I also encountered a similar 500 error in /api/docs/:

image

Could you please help me understand why this error is occurring and how to resolve it?

Are there known steps to reproduce?

No response

Originally created by @LukiaLiang on GitHub (Jan 7, 2025). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/2947 ### How are you running AnythingLLM? AnythingLLM desktop app ### What happened? I am testing to upload a file using `/api/v1/document/upload`. Below is the code I am using: ```python import requests import os api_url = "http://localhost:3001/api/v1/document/upload" headers = { "Authorization": "[My API Key]", "accept": "application/json" } pdf_filename = "temp.pdf" with open(pdf_filename, "rb") as f: files = {"file": (pdf_filename, f, "application/pdf")} print(f"Sending files: {pdf_filename}") response = requests.post(api_url, headers=headers, files=files) if response.status_code == 200: print("PDF successfully uploaded to the API.") else: print(f"Failed. Status code: {response.status_code}, Response: {response.text}") ``` The file `temp.pdf` exists in the same directory as the script. However, the program is returning the following error: ``` Sending files: temp.pdf Failed. Status code: 500, Response: {"success":false,"error":"Invalid file upload. ENOENT: no such file or directory, open 'C:\\Users\\[My Username]\\AppData\\Roaming\\collector\\hotdir\\temp.pdf'"} ``` In fact, I also encountered a similar 500 error in /api/docs/: ![image](https://github.com/user-attachments/assets/94e72233-6e4b-44a1-b8c3-d1df985c6d0a) Could you please help me understand why this error is occurring and how to resolve it? ### Are there known steps to reproduce? _No response_
yindo added the possible bug label 2026-02-22 18:26:58 -05:00
yindo closed this issue 2026-02-22 18:26:58 -05:00
Author
Owner

@timothycarambat commented on GitHub (Jan 7, 2025):

The swagger UI fails because of https://github.com/Mintplex-Labs/anything-llm/issues/2473 (Multi-part uploads)

As for your script - how does this work instead?

import requests
import os

api_url = "http://localhost:3001/api/v1/document/upload"
headers = {
    "Authorization": "[My API Key]",
    "accept": "application/json"
}

pdf_filename = "temp.pdf"
files = {'file': open(pdf_filename, 'rb')}
print(f"Sending files: {pdf_filename}")
response = requests.post(api_url, headers=headers, files=files)
if response.status_code == 200:
    print("PDF successfully uploaded to the API.")
else:
    print(f"Failed. Status code: {response.status_code}, Response: {response.text}")
@timothycarambat commented on GitHub (Jan 7, 2025): The swagger UI fails because of https://github.com/Mintplex-Labs/anything-llm/issues/2473 (Multi-part uploads) As for your script - how does this work instead? ```python import requests import os api_url = "http://localhost:3001/api/v1/document/upload" headers = { "Authorization": "[My API Key]", "accept": "application/json" } pdf_filename = "temp.pdf" files = {'file': open(pdf_filename, 'rb')} print(f"Sending files: {pdf_filename}") response = requests.post(api_url, headers=headers, files=files) if response.status_code == 200: print("PDF successfully uploaded to the API.") else: print(f"Failed. Status code: {response.status_code}, Response: {response.text}") ```
Author
Owner

@LukiaLiang commented on GitHub (Jan 7, 2025):

The result is exactly the same:
image

@LukiaLiang commented on GitHub (Jan 7, 2025): The result is exactly the same: ![image](https://github.com/user-attachments/assets/da52a0cb-6e95-4a71-b87e-23209c4651a6)
Author
Owner

@timothycarambat commented on GitHub (Jan 8, 2025):

Found the root cause. Will be patched in 1.7.2 release

@timothycarambat commented on GitHub (Jan 8, 2025): Found the root cause. Will be patched in 1.7.2 release
Author
Owner

@LukiaLiang commented on GitHub (Jan 9, 2025):

Thanks!

@LukiaLiang commented on GitHub (Jan 9, 2025): Thanks!
Author
Owner

@zhiruyu520 commented on GitHub (Feb 8, 2025):

Same question

@zhiruyu520 commented on GitHub (Feb 8, 2025): Same question
yindo changed title from [BUG]: Unable to Upload File via /api/v1/document/upload to [GH-ISSUE #2947] [BUG]: Unable to Upload File via /api/v1/document/upload 2026-06-05 14:43:13 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#1880