bn.uploadFile
▸ uploadFile(options): UploadTask
description Uploads local resources to the server. The client initiates a HTTPS POST Request, wherein content-type for multipart/form-data.
example
bn.chooseImage({
success (res) {
const tempFilePaths = res.tempFilePaths
bn.uploadFile({
url: 'https://example/upload', //Example only, not real interface address
filePath: tempFilePaths[0],
name: 'file',
formData: {
'user': 'test'
},
success (res){
const data = res.data
//of the something
}
})
}
})
Parameters
| Name | Type |
|---|---|
options | UploadFileOption |
Returns
UploadTask
UploadTask
Interface: UploadFileOption
| Name | Type | Description |
|---|---|---|
| url | string | Developer server address |
| filePath | string | Path to upload file resource (local path) |
| name | string | The key corresponding to the file, the developer can get the binary content of the file through this key on the server side |
| header? | Headers | Header of HTTP request, Referer cannot be set in Header |
| formData? | Record<string, string> | Other additional form data in the HTTP request |
| timeout? | number | Timeout time.default 2000 |
| method? | "POST" | "PUT" | remark sdk > 4.9.0; Method used when upload file, support 'POST' or 'PUT'. |
| complete? | UploadFileCompleteCallback | The callback function for the end of the interface call (it will be executed when the call succeeds or fails) |
| fail? | UploadFileFailCallback | The callback function of interface call failure |
| success? | UploadFileSuccessCallback | Callback function for successful interface call |
Interface: UploadTask
| Name | Type | Description |
|---|---|---|
| abort | (): void | Interrupt upload task |
| offHeadersReceived | (callback?): void | Cancel listening to the HTTP Response Header event |
| offProgressUpdate | (callback?): void | Cancel listening to upload progress change events |
| onHeadersReceived | (callback): void | Listen to the HTTP Response Header event. Will be earlier than the request completion event |
| onProgressUpdate | (callback): void | Listen to upload progress change events |