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

saveImageToGallery

Bắt đầu hỗ trợ ở phiên bản:

  • SDK: 2.16.0
import { saveImageToGallery } from "zmp-sdk/apis";

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!");
Xem hướng dẫn xử lý lỗi và bảng mô tả chi tiết mã lỗi tại đây.

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%.

saveImageToGallery

zi-chevron-up
miniapp-logo

Khám phá