Nhảy tới nội dung

my.saveImage

saveImage

my.saveImage là API dùng để lưu 1 remote image vào gallery của thiết bị di động.

Quét mã để trải nghiệm

Xem code mẫu trên Tini Studio

Demo

Trải nghiệm thử với trình giả lập bên dưới

API Params

Thuộc tínhKiểu dữ liệuBắt buộcMô tả
urlstringĐường dẫn của remote image.
successFunctionCallback function khi save hình ảnh thành công
failFunctionCallback function khi save image bất thành
completeFunctionCallback function khi gọi API hoàn tất bất kể việc save hình ảnh thành công hay thất bại.
Lưu ý
  • Image sẽ được lưu vào album Tiki-Miniapp.
  • Không hỗ trợ đường dẫn base64.

Sample Code

<view>
<block-header title="Usage" description="Save an image to gallery" />
<view class="block-content">
Input the url to download
<input class="form-value" placeholder="URL" name="url" onInput="urlChange"></input>
</view>
<view class="block-content">
<button class="button-full" onTap="onSaveImage">Save Image</button>
</view>
</view>
Page({
data: {
url: undefined
},
urlChange(e) {
this.setData({
url: e.detail.value
});
},
onSaveImage() {
my.saveImage({
url: this.data.url,
success: (res) => {
my.alert({
title: 'Saved!',
content: 'Check your gallery'
});
},
fail: (e) => {
console.log(e);
}
});
}
});