我正在尝试从服务器下载mp3文件,但应用程序崩溃了。文件被创建,获取文件中的一些数据然后崩溃。这是我正在尝试的:
var file = Ti.Filesystem.getFile(directory.nativePath(), filename);
var httpClient = Ti.Network.createHTTPClient();
httpClient.open('GET', URL);
httpClient.receive(function(data) {
var fileStream = Ti.Filesystem.getFileStream(file);
fileStream.open(Ti.Filesystem.MODE_WRITE, true);
fileStream.write(data);
fileStream.close();
});
感谢。
答案 0 :(得分:0)
这有效:
var file = Ti.Filesystem.getFile(directoryPath, filename);
var httpClient = Ti.Network.createHTTPClient();
httpClient.onload = function(e) {
file.open(Ti.Filesystem.MODE_WRITE);
file.write(this.responseData); // write to the file
}
httpClient.open('GET', URL);
httpClient.send();