def oparl_file_downloadUrl_data(params): file_data = db.get_file(deref={'values': ['file']}, search_params={'_id': ObjectId(params['file_id'])}) if len(file_data) == 0: # TODO: Rendere informativere 404 Seite abort(404) file_data = file_data[0] # 'file' property is not set (e.g. due to depublication) if 'file' not in file_data: if 'depublication' in file_data: abort(410) # Gone else: # TODO: log this as unexplicable... abort(500) handler = db.get_file_data(file_data['file']['_id']) response = make_response(handler.read(), 200) response.mimetype = file_data['mimetype'] response.headers['X-Robots-Tag'] = 'noarchive' response.headers['ETag'] = file_data['sha1Checksum'] response.headers['Last-modified'] = util.rfc1123date(file_data['file']['uploadDate']) response.headers['Expires'] = util.expires_date(hours=(24 * 30)) response.headers['Cache-Control'] = util.cache_max_age(hours=(24 * 30)) response.headers['Content-Disposition'] = 'attachment; filename=' + file_data['filename'] return response
def oparl_file_accessUrl_data(params): file_data = db.get_file(deref={'values': ['file']}, search_params={'_id': ObjectId(params['file_id'])}) if len(file_data) == 0: # TODO: Rendere informativere 404 Seite abort(404) file_data = file_data[0] # extension doesn't match file extension (avoiding arbitrary URLs) #proper_extension = attachment_info['filename'].split('.')[-1] #if proper_extension != extension: # abort(404) # 'file' property is not set (e.g. due to depublication) if 'file' not in file_data: if 'depublication' in file_data: abort(410) # Gone else: # TODO: log this as unexplicable... abort(500) # handle conditional GET #if 'If-Modified-Since' in request.headers: # file_date = attachment_info['file']['uploadDate'].replace(tzinfo=None) # request_date = util.parse_rfc1123date(request.headers['If-Modified-Since']) # difference = file_date - request_date # if difference < datetime.timedelta(0, 1): # 1 second # return Response(status=304) #if 'if-none-match' in request.headers: # print "Conditional GET: If-None-Match" # TODO: handle ETag in request handler = db.get_file_data(file_data['file']['_id']) response = make_response(handler.read(), 200) response.mimetype = file_data['mimetype'] response.headers['X-Robots-Tag'] = 'noarchive' response.headers['ETag'] = file_data['sha1Checksum'] response.headers['Last-modified'] = util.rfc1123date(file_data['file']['uploadDate']) response.headers['Expires'] = util.expires_date(hours=(24 * 30)) response.headers['Cache-Control'] = util.cache_max_age(hours=(24 * 30)) return response