Need help saving file from URL


#1

Hello, I am trying to do a simple mp3 file download off a webserver. I'm quite new and I need help getting from InputStream to an actual file saved on my hard drive.

URL myUrl (http://www.example.com/test.mp3);

InputStream* urlStream = myUrl.createInputStream(true);

<Not sure what to do next>

Saved into -> File(local_path/test.mp3);

 

Any and all help appreciated! Thanks.


#2

Okay, I think I got it... Here it is in case anyone else is interested or if you think I'm doing it all wrong (which is very possible).

 

URL fileUrl("http://someurl.com/somefile.mp3");

ScopedPointer<InputStream> fileStream = fileUrl.createInputStream(false);

File localFile("c:/somepath/test.mp3");

localFile.deleteFile();

MemoryBlock mem(1024);

fileStream->readIntoMemoryBlock(mem);

FileOutputStream out(localFile);

out.write(mem.getData(), mem.getSize());