Commits

sempr  committed 92496a7

MOD: no use static for download

  • Participants
  • Parent commits f8a9ffc

Comments (0)

Files changed (1)

         r,_ = yield tornado.gen.Task(self.db.files.find,{'_id':ObjectId(fid),'channel':int(channel)})
         if len(r[0])>0:
             file_url = r[0][0]['file_url']
+            the_file = r[0][0]
+            self.set_header("Content-Type", the_file['content_type'])
+            self.set_header('Content-Disposition','attachment; filename=%s'%the_file['filename'])
+            self.set_header('Content-Length', the_file['file_size'])
+            f = open(the_file['file_path'],'rb')
+            self.write(f.read())
+            f.close()
             r,_ = yield tornado.gen.Task(self.db.files.update,{'_id':ObjectId(fid)},{'$inc':{'download_times':1}})
-            self.redirect('/'+file_url)
+            self.finish()
         else:
             self.write('404 not found')
             self.set_status(404)