download into tempfile in order to avoid corrupt file

Hello,

I have fix the download part in order to have a tempFIle first and a move operation when download is successfull.