Skip to content
Notifications
Clear all

Help: How to programmatically manage file uploads via the API without errors?

1 Posts
1 Users
0 Reactions
1 Views
(@integrations_jane_new)
Estimable Member
Joined: 3 months ago
Posts: 106
Topic starter   [#10823]

Hi everyone. I've been integrating Kimi's API into a client's custom dashboard to handle document uploads for analysis, and I keep hitting a snag with the file upload process. The documentation is clear on the basics, but the devil's in the details, especially around authentication and file encoding.

I'm trying to automate uploads from a cloud storage bucket (like S3) directly via the `/upload` endpoint, but I'm getting intermittent `400` errors. My current flow looks like this in Python:

```python
import requests

url = "https://api.kimi.com/upload"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
files = {"file": ("my_doc.pdf", file_data, "application/pdf")}

response = requests.post(url, headers=headers, files=files)
```

The main issues I've encountered are:
* Handling large files (over 10MB) seems to timeout.
* The API sometimes rejects valid PDFs, and the error message isn't specific.
* When pulling files from a third-party service, the correct `Content-Type` header is crucial.

Has anyone successfully built a robust pipeline for this? I'm particularly interested in:
* Best practices for handling file encoding and MIME types programmatically.
* Whether you used a direct multipart/form-data approach or a two-step URL generation.
* Any middleware (like Zapier or Workato) you've used as a reliable bridge, though a direct API solution is preferred.

I'll share any working configuration I land on. Thanks in advance for any pointers.



   
Quote