API Documentation: Image Upload API
1. API Overview
This API is used to upload local image files to the system's image hosting server. Upon a successful upload, it typically returns an online access link (URL) for the image.
- Current Status: ?? Developing
2. API Details
- HTTP Method:
POST - Endpoint:
https://api.codingplanx.ai/api/upload - Content-Type:
multipart/form-data
3. Request Parameters
3.1 Request Headers
| Parameter | Required | Example | Description |
|---|---|---|---|
| Content-Type | Yes | multipart/form-data | Declares the request body as a form file upload format. |
3.2 Request Body
This API uses the multipart/form-data format to transmit data. The specific fields are as follows:
| Parameter | Type | Required | Example | Description |
|---|---|---|---|---|
| file | file (binary) | No* | C:\Users\...\d63ea1bd9011777e653b1addc7a88433.png | The image file to be uploaded. (*Note: Although marked as not required in the specification, it is practically required for the actual upload business logic to work.) |
4. Response Parameters
4.1 Response Status
- HTTP Status Code:
200 OK - Content-Type:
application/json
4.2 Response Data Structure
The specific fields for the response model are not yet defined (Schema is an empty object {}). Below is a general success response example:
{
"code": 200,
"message": "Success"
}
(Note: Once development is complete, this JSON object will typically include the image's URL, e.g., "url": "https://...")
5. Request Code Examples
To facilitate quick integration, below are calling examples in three common languages/tools:
5.1 cURL
curl --location --request POST 'https://api.codingplanx.ai/api/upload' \
--form 'file=@"/C:/Users/Administrator/Desktop/d63ea1bd9011777e653b1addc7a88433.png"'
5.2 Python (Requests)
import requests
url = "https://api.codingplanx.ai/api/upload"
payload={}
files=[
('file',('image.png',open('C:/Users/Administrator/Desktop/d63ea1bd9011777e653b1addc7a88433.png','rb'),'image/png'))
]
headers = {}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
5.3 JavaScript (Fetch API)
const myHeaders = new Headers();
const formdata = new FormData();
// Assuming fileInput is the <input type="file"> element in your HTML
formdata.append("file", fileInput.files[0], "d63ea1bd9011777e653b1addc7a88433.png");
const requestOptions = {
method: 'POST',
headers: myHeaders,
body: formdata,
redirect: 'follow'
};
fetch("https://api.codingplanx.ai/api/upload", requestOptions)
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.log('error', error));
6. Frequently Asked Questions (FAQs)
Q1: What image formats are supported for upload?
A: Generally, the image hosting API supports mainstream image formats such as
JPG,JPEG,PNG,GIF, andWebP. It is recommended to ensure the file extension and MIME type are correct when making a request. Specific restrictions are subject to the actual backend validation rules.
Q2: Is there a file size limit for image uploads?
A: Yes. Although not currently noted in the documentation, to ensure server stability, there are usually size limits on uploaded files (e.g., no more than 5MB or 10MB per image). If you upload a file that is too large, you may receive a
413 Payload Too LargeHTTP status code error.
Q3: Why am I getting a CORS (Cross-Origin) error when calling from the frontend?
A: This happens because the domain of your frontend page does not match the API domain (
api.codingplanx.ai), triggering the browser's Same-Origin Policy. Please contact the backend developers to configure the correctAccess-Control-Allow-Originresponse header on the server, or use a Proxy for local frontend development debugging.
Q4: The documentation states the file parameter is "not required". What happens if I don't send it?
A: In the current API definition,
fileis marked asrequired: false. If you omit this parameter, the API will still return a200 OKstatus code (based on the current design), but it cannot actually complete the image storage process. It is highly recommended to always include the file parameter in your business logic.
Q5: How do I get the image URL after a successful upload?
A: The API is currently in the
developingstate, and the returned JSON Schema is temporarily empty. Once development is complete, the development team will add return fields (such asurlordata.link) to the JSON of the200response body. Please keep an eye on future updates to this API documentation.