Chuyển tới nội dung chính

saveImageToGallery

import { saveImageToGallery } from "zmp-sdk/apis"; // >= 2.16.0

Lưu ảnh vào thư viện media của thiết bị.

Ví dụ

Thông báo một lần sau khi lưu ảnh xong:

await saveImageToGallery({
imageUrl: "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg",
});
console.log("Lưu ảnh thành công!");

Xử lý lỗi khi lưu ảnh:

try {
await saveImageToGallery({
imageUrl: "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg",
});
} catch (error) {
console.error(error);
}

Báo cáo tiến độ lưu ảnh:

await saveImageToGallery({
imageUrl: "https://sample-videos.com/img/Sample-jpg-image-50kb.jpg",
onProgress: (progress) => {
console.log(`Đã lưu được ${progress}%...`);
},
});
console.log("Lưu ảnh thành công!");

Tham số

Truyền tham số vào API dưới dạng object chứa các thuộc tính:

NameTypeDefaultDescription
imageBase64Datastring

Giá trị base64 của ảnh cần lưu.

imageUrlstring

Đường dẫn của ảnh cần lưu.

onProgress(progress: number) => void

Callback function tiến độ tải file. Với progress là số từ 0 đến 100%.

Errors

Bắt đầu hỗ trợ:

  • API phiên bản: 2.21.0
CodeMessageNote
-2005Unable to save media