android - C# - downloads get corrupted -


so have xamarin android application can download files server, images heavily distorted (screenshot below), videos can't played, audio sounds weird etc., of time gets downloaded properly. , distortions happen on mobile network, when downloading on wifi, happen less frequently. there wrong download code or maybe save location has it?

code downloading files:

public static async task downloadfileasync(string url, string mimetype, stream filestream) {     long receivedbytes = 0;     long totalbytes = 0;     webclient client = new webclient ();      using (var stream = await client.openreadtaskasync (url)) {         byte[] buffer = new byte[1024];         totalbytes = int64.parse (client.responseheaders [system.net.httpresponseheader.contentlength]);         (;;) {             int bytesread = await stream.readasync (buffer, 0, buffer.length);             await filestream.writeasync (buffer, 0, buffer.length);              if (bytesread == 0)             {                 await task.yield();                 break;             }              receivedbytes += bytesread;              //raise event             downloadprogressmade (receivedbytes, totalbytes);         }     } } 

and file gets saved this:

//act = activity, because downloads started fragment outfile = act.openfileoutput(filename, filecreationmode.worldreadable); await uploadhelper.downloadfileasync(url, mimetype, outfile); 

here screenshot of downloaded image: screenshot

update: not images distorted, other files corrupted - videos can't played , audio files sound weird.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -