Skip to content

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:

ts
const http = axios.create({
	adapter: createUniAppAxiosAdapter(),
});

Routing rules:

Axios methoduni APIPlatform request method
uploaduni.uploadFilePOST
downloaduni.downloadFileGET
Other methodsuni.requestOriginal HTTP method

See the uni-app adapter guide for platform fields, progress, cancellation, and response behavior.

axios.upload() Upload ​

ts
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 ​

ts
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 ​

ts
createUniAppAxiosAdapter(): AxiosAdapter;

Example ​

ts
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 ​

ValueTypeDescription
resultAxiosAdapterFunction assignable to Axios adapter.

axios.upload Upload ​

Uploads a file using the Axios extension installed when the uni-app adapter is first created.

Signature ​

ts
upload<T, R, D>(url: string, data?: D, config?: AxiosRequestConfig<D>): Promise<R>;

Example ​

ts
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 ​

InputTypeRequired / defaultDescription
urlstringRequiredUpload URL.
dataDOptionalOrdinary multipart form fields.
configAxiosRequestConfig<D>OptionalfilePath, name, files, and other Axios settings.

Returns ​

ValueTypeDescription
resultPromise<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 ​

ts
download<T, R, D>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;

Example ​

ts
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 ​

InputTypeRequired / defaultDescription
urlstringRequiredDownload URL.
configAxiosRequestConfig<D>OptionalAxios and uni-app platform request options.

Returns ​

ValueTypeDescription
resultPromise<R>AxiosResponse whose data is a temporary file path.