def send_storage_file( get_local_path, open_file, prefix, preview_file_id, extension, mimetype="application/octet-stream", as_attachment=False, ): """ Send file from storage. If it's not a local storage, cache the file in a temporary folder before sending it. It accepts conditional headers. """ file_path = fs.get_file_path( config, get_local_path, open_file, prefix, preview_file_id, extension ) attachment_filename = "" if as_attachment: attachment_filename = names_service.get_preview_file_name( preview_file_id ) try: return flask_send_file( file_path, conditional=True, mimetype=mimetype, as_attachment=as_attachment, attachment_filename=attachment_filename, ) except IOError as e: current_app.logger.error(e) raise FileNotFound
def get(self, playlist_id, build_job_id): playlist = playlists_service.get_playlist(playlist_id) project = projects_service.get_project(playlist["project_id"]) build_job = playlists_service.get_build_job(build_job_id) user_service.check_manager_project_access(playlist["project_id"]) if build_job["status"] != "succeeded": return {"error": True, "message": "Build is not finished"}, 400 else: movie_file_path = fs.get_file_path( config, file_store.get_local_movie_path, file_store.open_movie, "playlists", build_job_id, "mp4", ) context_name = slugify.slugify(project["name"], separator="_") if project["production_type"] == "tvshow": episode = shots_service.get_episode(playlist["episode_id"]) context_name += "_%s" % slugify.slugify(episode["name"], separator="_") attachment_filename = "%s_%s_%s.mp4" % ( slugify.slugify(build_job["created_at"], separator="").replace( "t", "_"), context_name, slugify.slugify(playlist["name"], separator="_"), ) return flask_send_file( movie_file_path, conditional=True, mimetype="video/mp4", as_attachment=True, attachment_filename=attachment_filename, )
def get_attachment_file_path(attachment_file): """ Get attachement file path when stored locally. """ return fs.get_file_path(config, file_store.get_local_file_path, file_store.open_file, "attachments", attachment_file["id"], attachment_file["extension"])
def send_storage_file(working_file_id, as_attachment=False): """ Send file from storage. If it's not a local storage, cache the file in a temporary folder before sending it. It accepts conditional headers. """ prefix = "working" extension = "tmp" get_local_path = file_store.get_local_file_path open_file = file_store.open_file mimetype = "application/octet-stream" file_path = fs.get_file_path( config, get_local_path, open_file, prefix, working_file_id, extension ) attachment_filename = "" if as_attachment: attachment_filename = working_file_id try: return flask_send_file( file_path, conditional=True, mimetype=mimetype, as_attachment=as_attachment, attachment_filename=attachment_filename, ) except IOError as e: current_app.logger.error(e) return ( { "error": True, "message": "Working file not found for: %s" % working_file_id, }, 404, ) except FileNotFound: return ( { "error": True, "message": "Working file not found for: %s" % working_file_id, }, 404, )