关于hms-core:Runtime快游戏调用copyfile接口写临时文件踩坑记录

问题形容:

调用copyfile接口将临时文件写入到缓存报错“no such file or directory”。

问题剖析:

如果调用copyfile接口应用的源文件是临时文件,则该接口目前不反对此场景,须要应用save接口先将临时文件保留到本地,而后再调用copyfile接口。

解决办法:

var fileSystemManager = hbs.getFileSystemManager();
fileSystemManager.saveFile({
    tempFilePath: ‘temp file path’,
        filePath: ‘target file path’,
            success : function(res) {
                    console.log("saveFile success res = " + JSON.stringify(res));    
                    },    
                    fail : function(data) {        
                    console.log("saveFile fail " + JSON.stringify(data));    
                    },    
                    complete : function() {        
                    console.log("saveFile complete" );    
                    }}) 
                    fileSystemManager.copyFile({    
                    srcPath : ‘source file’,  //源文件门路,只能够是本地文件    
                    destPath : ‘target path’,    
                    success : function() {        
                    console.log("copy success" );    
                    },    
                    fail : function(data) {        
                    console.log("copy fail " + JSON.stringify(data));    
                    },    
                    complete : function() {        
                    console.log("copy complete" );    
                    }})

原文链接:https://developer.huawei.com/consumer/cn/forum/topic/0204404942804220219?fid=18

原作者:AppGallery Connect

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理