简体   繁体   English

Appcelerator-文件存储失败

[英]Appcelerator - File storage fail

I copy a video into /Documents/videos/xxxxxx.mp4 and then, when I close the app and restart it, this error appear when I want to get the file: 我将视频复制到/Documents/videos/xxxxxx.mp4,然后在关闭应用程序并重新启动时,当我要获取文件时出现此错误:

nativeReason = "Could not open file stream for file at path: /var/mobile/Containers/Data/Application/055CE45C-28EC-46F5-9609-F16E357B682E/Documents/videos/1458044667778.mp4\nFile does not exist at path /var/mobile/Containers/Data/Application/055CE45C-28EC-46F5-9609-F16E357B682E/Documents/videos/1458044667778.mp4";

But I can see this file at the directory: 但我可以在目录中看到此文件:

在此处输入图片说明

Whats the problem?? 有什么问题?? This occur on iOS, Ti.SDK 5.2.0.GA 这发生在iOS Ti.SDK 5.2.0.GA

My code: 我的代码:

            if(OS_IOS){
                Ti.API.debug("Media: " + this.get("media").nativePath);
                var infile = Ti.Filesystem.getFile(this.get("media").nativePath); //!
            }else{
                var infile = Ti.Filesystem.getFile(this.get("media"));
            }
            Ti.API.debug('infile: ' + infile.exists());

            var tempFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "videos/");

            if(!tempFile.exists())
                tempFile.createDirectory(); //create videos directory

            var tempFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "videos/" + new Date().getTime() + ".mp4");
            Ti.API.debug('tempFile ' + tempFile.exists()); // tempsFile is always empty

            if(OS_IOS){

                if (infile.exists() && (!tempFile.exists()) ) { //copy infile to videos/
                    tempFile.write(infile.read());
                }

            }else{ //Android

                infile.copy(tempFile.nativePath); //copy infile to videos/
            }   

//Get video, the path saved is correct
    var vid = Ti.Filesystem.getFile(video.get("videoFile"));

By default Ti.Filesystem.getFile() all relative paths are currently interpreted as relative to the Resources directory, not to the current context. 默认情况下,Ti.Filesystem.getFile()当前将所有相对路径解释为相对于Resources目录,而不是相对于当前上下文。 This is a known issue that will be addressed in a future release. 这是一个已知问题,将在以后的版本中解决。 : http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-method-getFile http : //docs.appcelerator.com/platform/latest/#!/api/Titanium.Filesystem-method-getFile

So, you need to save the video file name in video.get("videoFile") and get the video this way : Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "videos/"+video.get("videoFile")); 因此,您需要将视频文件名保存在video.get("videoFile")并以这种方式获取视频: Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "videos/"+video.get("videoFile"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM