| 207 | apis_user_list = ['api_enabled_builder', 'security_email_verified']) |
| 208 | @limiter.limit("3 per day") |
| 209 | def update_overlay_image_api(project_string_id): |
| 210 | file = request.files.get('file') |
| 211 | if not file: |
| 212 | return "No file", 400 |
| 213 | |
| 214 | extension = os.path.splitext(file.filename)[1].lower() |
| 215 | if extension in images_allowed_file_names: |
| 216 | |
| 217 | file.filename = secure_filename( |
| 218 | file.filename) # http://flask.pocoo.org/docs/0.12/patterns/fileuploads/ |
| 219 | temp_dir = tempfile.mkdtemp() |
| 220 | file_name = temp_dir + "/" + file.filename |
| 221 | file.save(file_name) |
| 222 | |
| 223 | action_id = request.headers['action_id'] |
| 224 | if action_id is None: |
| 225 | return "error no action_id", 400 |
| 226 | |
| 227 | with sessionMaker.session_scope() as session: |
| 228 | |
| 229 | project = Project.get(session, project_string_id) |
| 230 | |
| 231 | action = Action.get_by_id( |
| 232 | session = session, |
| 233 | id = action_id, |
| 234 | project_id = project.id) |
| 235 | |
| 236 | with open(file_name, "rb") as file: |
| 237 | content_type = "image/" + str(extension) |
| 238 | short_file_name = os.path.split(file_name)[1] |
| 239 | |
| 240 | action.overlay_image = process_image_for_overlay( |
| 241 | session = session, |
| 242 | file = file, |
| 243 | file_name = short_file_name, |
| 244 | blob_base = "actions/overlay_images/", |
| 245 | content_type = content_type, |
| 246 | extension = extension) |
| 247 | |
| 248 | session.add(action) |
| 249 | |
| 250 | return jsonify(success = True, |
| 251 | action = action.serialize()), 200 |
| 252 | |
| 253 | return jsonify(success = False), 400 |
| 254 | |
| 255 | |
| 256 | from shared.database.image import Image |