from flask.ext import restful
from . import database
from flask import abort, send_file
from werkzeug import secure_filename
import os


class DownloadInstance(restful.Resource):
    def get(self, id):
        document = database.get_document(id)
        if document is None:
            abort(404)
        return send_file(document['path'])


from flask.ext import restful
from . import database
from flask import abort, send_file
import mimetypes


class DownloadInstance(restful.Resource):
    def get(self, id):
        document = database.get_document(id)
        if document is None:
            abort(404)
        mt = mimetypes.guess_type(document['path'])[0]
        return send_file(document['path'],
                         as_attachment=True,
                         attachment_filename=document['name'],
                         mimetype=mt)

Make sure we give people a download with the actual name of the file
Make sure we give people a download with the actual name of the file

  from flask.ext import restful
  from . import database
  from flask import abort, send_file
+ import mimetypes
- from werkzeug import secure_filename
- import os
  
  
  class DownloadInstance(restful.Resource):
      def get(self, id):
          document = database.get_document(id)
          if document is None:
              abort(404)
+         mt = mimetypes.guess_type(document['path'])[0]
-         return send_file(document['path'])
+         return send_file(document['path'],
+                          as_attachment=True,
+                          attachment_filename=document['name'],
+                          mimetype=mt)
  
- 
Make sure we give people a download with the actual name of the file
## Code Before:
from flask.ext import restful
from . import database
from flask import abort, send_file
from werkzeug import secure_filename
import os


class DownloadInstance(restful.Resource):
    def get(self, id):
        document = database.get_document(id)
        if document is None:
            abort(404)
        return send_file(document['path'])


## Instruction:
Make sure we give people a download with the actual name of the file
## Code After:
from flask.ext import restful
from . import database
from flask import abort, send_file
import mimetypes


class DownloadInstance(restful.Resource):
    def get(self, id):
        document = database.get_document(id)
        if document is None:
            abort(404)
        mt = mimetypes.guess_type(document['path'])[0]
        return send_file(document['path'],
                         as_attachment=True,
                         attachment_filename=document['name'],
                         mimetype=mt)
