chooseImage
Bắt đầu hỗ trợ ở phiên bản:
- API: 2.23.4
Lưu ý
Với API version ﹤ 2.23.0, phải gọi api login trước khi gọi api này và cần xin cấp quyền tại trang Quản lý ứng dụng
Chọn hình ảnh từ album hoặc camera
Parameters
Object object
Property | Type | Default | Required | Description | Minimum Version |
---|---|---|---|---|---|
sourceType | string[] | Nguồn chọn hình ảnh, với các giá trị hợp lệ:
| 2.23.4 | ||
cameraType | string | Xác định camera cần mở với các giá trị hợp lệ:
| 2.23.4 | ||
success | function(Output) | Callback function khi gọi api thành công | 2.23.4 | ||
fail | function | Callback function khi gọi api thất bại | 2.23.4 |
Output object
Property | Type | Default | Required | Description | Minimum Version |
---|---|---|---|---|---|
filePaths | string[] | Đường dẫn các file đã chọn | 2.23.4 | ||
tempFiles | Array<TempFile> | Thông tin các temp files | 2.23.4 |
TempFile object
Property | Type | Default | Required | Description | Minimum Version |
---|---|---|---|---|---|
path | string | Đường dẫn các temp file đã chọn | 2.23.4 | ||
size | number | Kích thước các temp file đã chọn | 2.23.4 |
Sample Code
import api from "zmp-sdk";
api.chooseImage({
sourceType: ["album", "camera"],
cameraType: "back",
success: ({ filePaths, tempFiles }) => {
// xử lý khi gọi api thành công
},
fail: (error) => {
// xử lý khi gọi api thất bại
console.log(error);
},
});
// hoặc
async () => {
try {
const { filePaths, tempFiles } = await api.chooseImage({
sourceType: ["camera"],
cameraType: "front",
});
} catch (error) {
// xử lý khi gọi api thất bại
console.log(error);
}
};