如何检查url.createobjecturl生成的uri是否在打字稿中仍处于活动状态

问题描述 投票:1回答:1

我将一些图片存储为blob。我使用url.createobjecturl()函数在应用程序中显示它们。

但是过一会儿,这些生成的图像将被清除,如何测试它们是否仍处于活动状态?

如果它们是活动的,请继续使用它们,如果不活动,请重新构建uri。

Im使用离子2,带有打字稿的角度2。

javascript typescript angular blob ionic2
1个回答
0
投票

这是我使用JavaScript的方式:

                fetch(itemObjectURL)
                .then(function checkForBlobHealth(blob){
                    if (!blob.ok) {
                        console.log('❗ ' + itemObjectURL + ': Local media file not present')
                        //Take care of the situation, recreate or revoke ObjectURL
                    } else {
                        // Move on as usual
                    }
                })
© www.soinside.com 2019 - 2024. All rights reserved.