FileSystemManager.stat

2020-08-26 16:18 更新

解釋:獲取文件 Stats 對象。

Web 態(tài)說明:受瀏覽器限制,Web 態(tài)不支持文件系統(tǒng)相關功能,調用該方法會執(zhí)行失敗回調函數(shù)。

方法參數(shù):Object object

object參數(shù)說明:

success 返回參數(shù)說明:

stats 返回值說明

示例 

在開發(fā)者工具中打開


圖片示例

代碼示例

<view class="wrap">
    <button type="primary"  bindtap="stat">獲取文件 Stats 對象</button>
</view>
Page({
    data: {
        filePath: ''
    },
    onLoad() {
        this.fileSystemManager = swan.getFileSystemManager();
        swan.downloadFile({
            url: 'https://smartprogram.baidu.com/docs/img/logo.png',
            success: res => {
                swan.showToast({
                    title: `文件預下載完成,臨時路徑為${res.tempFilePath}`,
                    icon: 'none'
                });
                // 此為 “本地臨時文件” 路徑。
                console.log(res.tempFilePath);
                this.data.filePath = res.tempFilePath;
            }
        });
    },
    stat() {
        this.fileSystemManager.stat({
            path: this.data.filePath,
            // path: `${swan.env.USER_DATA_PATH}/demo.txt`,// 本地文件路徑
            success: res => {
                swan.showModal({
                    title: 'stat',
                    content: JSON.stringify(res)
                });
                console.log('stat success', res);
            },
            fail: err => {
                swan.showToast({
                    title: JSON.stringify(err),
                    icon: 'none'
                });
                console.log('stat fail', err);
            }
        });
    }
});


以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號