I've used examples from here Download a file with Adobe AIR and built app that downloads files from server.
I'll try to explain error by steps.
1) Adobe Air app downloaded xml file from server http://example.com/data/init.xml
2) I've opened it and all ok.
3) Adobe Air app again downloaded the same file from server. Now, if I open it with Notepad it says that init.xml is binary file. If I remove init.xml from disk and try again - the same. init.xml is a binary file. Reopen air app doesn't work.
4) I changed init.xml on server to init123.xml and downloaded it again. init123.xml was opened as normal xml file. If I again download it, then step 3 - init123.xml is a binary file.
Where could be the error?
Thank you.
OS - Windows 7
MD5 of files also changed.
This could be solved it I add random number to the end of url.
urlStream.load(new URLRequest(remoteFile+'?'+Math.random()));
but this
urlStream.load(new URLRequest(remoteFile));
makes file binary if I load it second time.
Source
private function startDownloading():void
{
destFile.nativePath = destDirectory +destFileBase;
fileStream = new FileStream();
fileStream.addEventListener(OutputProgressEvent.OUTPUT_PROGRESS, outputProgress);
fileStream.addEventListener(IOErrorEvent.IO_ERROR, fileAccessError);
fileStream.openAsync(destFile, FileMode.WRITE);
urlStream = new URLStream();
urlStream.addEventListener(ProgressEvent.PROGRESS, progress);
urlStream.addEventListener(Event.COMPLETE, complete);
urlStream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, urlStreamSecurityError);
urlStream.addEventListener(IOErrorEvent.IO_ERROR, urlStreamIOError);
urlStream.load(new URLRequest(remoteFile));
}
protected function fileAccessError(event:IOErrorEvent):void
{
urlStream.close();
fileStream.close();
}
protected function outputProgress(event:OutputProgressEvent):void
{
if(event.bytesPending == 0 && downloadCompleteFlag ) {
}
}
protected function urlStreamIOError(event:IOErrorEvent):void
{
trace('error 2');
}
protected function urlStreamSecurityError(event:SecurityErrorEvent):void
{
trace('error 2');
}
protected function progress(event:ProgressEvent):void
{
var bytes :ByteArray = new ByteArray();
var thisStart :uint = currentPosition;
currentPosition += urlStream.bytesAvailable;
urlStream.readBytes( bytes, thisStart );
fileStream.writeBytes( bytes, thisStart );
}
protected function complete(event:Event):void
{
urlStream.close();
fileStream.close();
downloadCompleteFlag = true;
}