uni-app adapter
UniAppRequestOptions and UniAppUploadFile
UniAppRequestOptions augments AxiosRequestConfig with adapter-forwarded platform options for SSL, HTTP/2, QUIC, HttpDNS, cookies, caching, redirects, uploads, and multiple files. UniAppUploadFile describes an individual files entry.
These declarations retain a platform-neutral projection of the native uni-app options, checked by type tests. Existing type names remain available, and ordinary consumers do not depend on UniNamespace. The adapter reuses native types internally, with cancellation requiring only the task's abort() capability. Broad native header and formData declarations do not weaken the SDK's existing constraints. Applications needing the full uni API declarations should install @dcloudio/types themselves.
The adapter copies Axios headers before converting uni options. Applying Basic Auth or removing upload Content-Type does not mutate the original config.headers.
createUniAppAxiosAdapter() Create
Returns an AxiosAdapter and installs file convenience methods once on the current Axios package prototype:
const http = axios.create({
adapter: createUniAppAxiosAdapter(),
});Routing rules:
| Axios method | uni API | Platform request method |
|---|---|---|
upload | uni.uploadFile | POST |
download | uni.downloadFile | GET |
| Other methods | uni.request | Original HTTP method |
See the uni-app adapter guide for platform fields, progress, cancellation, and response behavior.
axios.upload() Upload
upload<T, R, D>(url, data?, config?): Promise<R>Sets method to upload. Data contains ordinary multipart fields; filePath, name, files, and other file options belong in config.
axios.download() Download
download<T, R, D>(url, config?): Promise<R>Sets method to download. On success, response.data is the temporary file path returned by uni-app.
createUniAppAxiosAdapter Create
Creates an adapter routing Axios requests to uni.request, uploadFile, or downloadFile.
Signature
createUniAppAxiosAdapter(): AxiosAdapter;Example
import axios from "axios";
import { createUniAppAxiosAdapter } from "@fast-china/axios";
const result = createUniAppAxiosAdapter();
const http = axios.create({ adapter: result });Input
This method has no input parameters.
Returns
| Value | Type | Description |
|---|---|---|
result | AxiosAdapter | Function assignable to Axios adapter. |
axios.upload Upload
Uploads a file using the Axios extension installed when the uni-app adapter is first created.
Signature
upload<T, R, D>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;Example
import axios from "axios";
import { createUniAppAxiosAdapter } from "@fast-china/axios";
const http = axios.create({ adapter: createUniAppAxiosAdapter() });
const tempPath = "/tmp/avatar.png";
const result = await http.upload("/files", { category: "avatar" }, { filePath: tempPath, name: "file" });Input
| Input | Type | Required / default | Description |
|---|---|---|---|
url | string | Required | Upload URL. |
data | D | Optional | Ordinary multipart form fields. |
config | AxiosRequestConfig<D> | Optional | filePath, name, files, and other Axios settings. |
Returns
| Value | Type | Description |
|---|---|---|
result | Promise<R> | AxiosResponse converted from uni.uploadFile results. |
axios.download Download
Downloads a file using the Axios extension installed when the uni-app adapter is first created.
Signature
download<T, R, D>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;Example
import axios from "axios";
import { createUniAppAxiosAdapter } from "@fast-china/axios";
const http = axios.create({ adapter: createUniAppAxiosAdapter() });
const result = await http.download("/reports/1");
console.log(result.data);Input
| Input | Type | Required / default | Description |
|---|---|---|---|
url | string | Required | Download URL. |
config | AxiosRequestConfig<D> | Optional | Axios and uni-app platform request options. |
Returns
| Value | Type | Description |
|---|---|---|
result | Promise<R> | AxiosResponse whose data is a temporary file path. |
