使用“localhost”而不是“app://”来显示TideSDK中的文件

时间:2014-05-11 11:44:19

标签: javascript filestream httpserver tidesdk

有没有办法使用'localhost'地址代替'app://'来加载/显示文件?

我的意思是: http.://localhost/com.app/file.swf

我尝试过使用HTTPServer& TideSDK文档中列出了FileStream,但每次尝试加载文件时,整个应用都会被屏蔽并停止响应。

server = Ti.Network.createHTTPServer();

//Specify port number and callback function
//This example can be tested by pointing your
//browser to http://localhost:8082/

server.bind(8082,'localhost',function(request,response) {

//Serve desired file
var contents,
    contentType,
    readFi = Ti.Filesystem.getFile(Ti.App.getHome()+'/flash',request.getURI());


if (readFi.exists())
{
   var Stream = Ti.Filesystem.getFileStream(readFi);    
   Stream.open(Ti.Filesystem.MODE_READ);     
   contents =Stream.read(); 
   Stream.close();    
}



response.setContentType("application/x-shockwave-flash");

//Setting content length of the response
response.setContentLength(readFi.size());

//Setting status and reason
response.setStatusAndReason('200','OK');

//Finally writing the response back 
response.write(contents);
});

0 个答案:

没有答案