当用户拿相机时,文件存储在tempDirectory文件夹中。该文件已重命名,并已移至appImages文件夹(在applicationDataDirectory中)。这http://docs.appcelerator.com/platform/latest/#!/guide/Filesystem_Access_and_Storage很有帮助。
以下代码完全适用于Android,但使用iOS时,文件仅重命名,但不会移动。有任何想法吗?
var fs = Ti.Filesystem;
var imageDir = fs.getFile(fs.applicationDataDirectory,'appImages');
if (! imageDir.exists()) {
imageDir.createDirectory();
}
var tempFile = fs.getFile(fs.tempDirectory,timeStamp + "_" + registeredUserID + "_nomination.jpg");
tempFile.rename(nid + "_" + registeredUserID + "_nomination.jpg"); //renames nomination image
tempFile = fs.getFile(fs.tempDirectory,nid + "_" + registeredUserID + "_nomination.jpg"); //gets the new handler
tempFile.move("appImages/" + nid + "_" + registeredUserID + "_nomination.jpg"); //moves nomination image
var tempListAfter = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory).getDirectoryListing();
Ti.API.info("tempListAfter AFTER moving: " + JSON.stringify(tempListAfter));
var appImagesListAfter = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'appImages').getDirectoryListing();
Ti.API.info("appImagesListAfter AFTER moving: " + JSON.stringify(appImagesListAfter)); //iOS results an empty array, but works in Android and shows the properly named files in Android
tempFile = tempThumbFile = null;
解决方案基于Mituls建议:
tempFile.move(imageDir.nativePath + nid + "_" + registeredUserID + "_nomination.jpg");
答案 0 :(得分:1)
我认为您应该使用imageDir.nativePath移动tempFile,如
tempFile.move(imageDir.nativePath);