def create(): if "image" not in request.files: flash( "You haven't selected an image. Please choose one and try again.") return redirect(url_for('images.new')) file = request.files["image"] if file and allowed_file(file.filename): file.filename = secure_filename(file.filename) output = upload_file_to_s3(file, Config.S3_BUCKET) upload_image = Image(image=file.filename, user_id=current_user.id) if upload_image.save(): flash("Successfully uploaded your image!") return redirect( url_for("users.show", username=current_user.username)) else: flash('An error occurred. Try again') return render_template('images/new.html') else: for error in upload_image.errors: flash(error) return redirect(url_for("images.new"))
def upload(): if not 'profile_image' in request.files: flash('No images has been provided', 'warning') return redirect(url_for('users.user_profile', id=current_user.id)) file = request.files.get('profile_image') # image = request.files.get('image') new_image = Image.open(file) resized_image = ImageOps.fit(new_image, (500, 500), method=3, bleed=0.0, centering=(0.5, 0.5)) temp_storage = f"./instagram_web/static/temp/{file.filename}" resized_image.save(temp_storage) file.filename = secure_filename(file.filename) if not upload_file_to_s3(temp_storage, file): flash('Ops x loading!') return redirect(url_for('users.user_profile', id=current_user.id)) user = User.get_or_none(User.id == current_user.id) user.profile_image = file.filename user.save() breakpoint() os.remove(temp_storage) flash('Upload success!', 'success') return redirect(url_for('users.user_profile', id=current_user.id))
def story_post(id): upload_user = User.get_by_id(id) # story_file = request.form.get('story_file') message = request.form.get('message') if current_user.id != upload_user.id: flash("You are not Authorized to Do this") return render_template('/users/story.html', id=current_user.id) if 'story_file' not in request.files: flash("No File Found") return redirect(url_for('users.story', id=current_user.id)) file = request.files['story_file'] if file.filename == "": flash("Please Select a file") return redirect(url_for('users.story', id=current_user.id)) file.filename = secure_filename(file.filename) if not upload_file_to_s3(file): flash("Opps, Something wrong with the Uploading") return redirect(url_for('users.story', id=current_user.id)) new_story = Story(msg=message, story_image=file.filename, user=upload_user) new_story.save() flash("You Just Posted a new Story") return redirect(url_for('users.show', id=id))
def upload_file(id): # user_file = request.form.get("user_file") # breakpoint() editing_user = User.get_by_id(id) #check Authentication if current_user.id != editing_user.id: flash("You are not authorized to do this") return redirect(url_for('users.show', id=current_user.id)) if "user_file" not in request.files: flash("No File Found") return redirect(url_for('users.edit', id=id)) file = request.files["user_file"] if file.filename == "": flash("Please Select a file") return redirect(url_for('users.edit', id=id)) file.filename = secure_filename(file.filename) if not upload_file_to_s3(file): flash("Opps, Something wrong with the Uploading") return redirect(url_for('users.edit', id=id)) #else succeded upload file to AMAZON S3 editing_user.profile_image = file.filename editing_user.save() flash("Uploaded file succeed") # return redirect(url_for('users.edit', id = id)) return redirect(url_for('users.edit', id=id))
def upload_profile(): user = current_user if "user_profile_picture" not in request.files: flash('No user_file key in request.files') return redirect('/') file = request.files["user_profile_picture"] if file and allowed_file(file.filename): file.filename = secure_filename(file.filename) output = upload_file_to_s3(file, Config.S3_BUCKET) user.user_profile_image = file.filename update_user_image = User.update( user_profile_image=file.filename).where(User.id == current_user.id) if update_user_image.execute(): flash("Success!") return redirect(url_for("users.edit", id=current_user.id)) else: for error in user.errors: flash(error) return redirect(url_for("users.edit", id=current_user.id)) else: flash( "That's not an allowed extension. Please upload only JPGs, JPEGs, GIFs, PNGs and PDFs." ) return redirect(url_for("users.edit", id=current_user.id))
def usr_img_upload(): usr_img = request.files.get('user_image') if not 'user_image' in request.files: flash('no image has been provided', 'danger') return redirect(url_for('sessions.new')) if not upload_file_to_s3(usr_img): file.filename = secure_filename(usr_img.filename) flash('Oops! Something went wrong while uploading', 'warning') return redirect(url_for('sessions.new')) else: user = User.get_or_none(User.id == current_user.id) caption = request.form.get('img_caption') user_img = Image( user=user.id, user_img=usr_img.filename, caption=caption) user_img.save() flash('Image successfully uploaded!', 'success') return redirect(url_for('sessions.new'))
def upload_images(): if "user_image" not in request.files: flash('No image has been provided', 'warning') return redirect(url_for('session.new')) file = request.files.get("user_image") caption = request.form.get("caption") file.filename = secure_filename(file.filename) if not upload_file_to_s3(file): flash('Oops, something went wrong while uploading', 'warning') return redirect(url_for('sessions.new')) user = User.get_or_none(User.id == current_user.id) img_upload = Image(user=user.id, user_image=file.filename, caption=caption) img_upload.save() flash('Successfully uploaded Image', 'success') return redirect(url_for('sessions.new'))
def upload(): if "profile_image" not in request.files: flash('No image has been provided', 'warning') return redirect(url_for('users.edit', id=current_user.id)) file = request.files.get("profile_image") file.filename = secure_filename(file.filename) if not upload_file_to_s3(file): flash('Oops, something went wrong while uploading', 'warning') return redirect(url_for('users.edit', id=current_user.id)) user = User.get_or_none(User.id == current_user.id) user.profile_image = file.filename user.save() flash('Successfully uploaded profile Image', 'success') return redirect(url_for('users.edit', id=user.id))
def create(): auth_header = request.headers.get("Authorization") if auth_header: auth_token = auth_header.split(" ")[1] else: responseObject = { 'status': 'failed', 'message': 'No authorization header found' } return make_response(jsonify(responseObject)), 401 user_id = User.decode_auth_token(auth_token) user = User.get_or_none(id=user_id) file = request.files["image"] if user: if file and allowed_file(file.filename): output = upload_file_to_s3(file, Config.S3_BUCKET) upload_image = Image(image=file.filename, user=user.id) upload_image.save() responseObject = { "success": "ok!", "message": "Your photo successfully upploaded!" } return make_response(jsonify(responseObject)), 201 else: responseObject = { "status": "failed", "message": "Authentication failed!" } return make_response(jsonify(responseObject)), 401
def create(): if not 'image' in request.files: flash('No images has been provided', 'warning') return redirect(request.referrer) file = request.files.get('image') file.filename = secure_filename(file.filename) caption = request.form.get("caption") if not upload_file_to_s3(file): flash('Ops x loading!') return redirect(request.referrer) image = Photos(filename=file.filename, caption=caption, user=current_user.id) if not image.save(): flash('Didnt managed to upload') return redirect(request.referrer) flash('Upload success!', 'success') return redirect(request.referrer)
def profimg_upload(): file = request.files.get('profile_image') if not 'profile_image' in request.files: flash('no image has been provided', 'danger') return redirect(url_for('sessions.prof_info', id=current_user.id)) if not upload_file_to_s3(file): file.filename = secure_filename(file.filename) flash('Oops! Something went wrong while uploading', 'warning') return redirect(url_for('sessions.prof_info', id=current_user.id)) # else: # flash('upload complete') # return redirect(url_for('sessions.prof_info', id=current_user.id)) else: user = User.get_or_none(User.id == current_user.id) user.profile_image = file.filename user.save() flash('successfully added profile image!', 'success') return redirect(url_for('sessions.prof_info', id=current_user.id))