Example #1
0
def upload_img(username):
    images = list(Image.select().join(User).where(
        User.username == current_user.username))
    user = User.get_or_none(User.username == current_user.username)
    follow = Following.get_or_none(Following.fan_id == current_user.id
                                   and Following.idol_id == user.id)

    try:
        file = request.files.get("user_file")
        s3.upload_fileobj(file, S3_BUCKET, file.filename)
        flash("successfully updated")

        p = Image(description=request.form['description'],
                  user_id=current_user.id,
                  img_path=file.filename)
        p.save()
        return redirect(
            url_for("users.show",
                    images=images,
                    user=user,
                    username=username,
                    follow=follow))

    except:
        return 'failed'
        flash("Something went wrong!!")
        return render_template("users/show.html", images=images, user=user)
Example #2
0
def upload_file_to_s3(file, bucket_name, acl="public-read"):

    s3.upload_fileobj(file,
                      bucket_name,
                      file.filename,
                      ExtraArgs={
                          "ACL": acl,
                          "ContentType": file.content_type
                      })
    return "https://s3.eu-north-1.amazonaws.com/meemiarkistobucket/{}".format(
        file.filename)
Example #3
0
def upload_image_update(id):
    file = request.files.get("user_file")
    s = Image(user=id, image_url=file.filename)
    s.save()
    s3.upload_fileobj(file,
                      "nextagramtao",
                      file.filename,
                      ExtraArgs={
                          "ACL": "public-read",
                          "ContentType": file.content_type
                      })
    return redirect(url_for('users.show', name=current_user.name))
Example #4
0
def profile_pic_update(id):

    file = request.files.get("user_file")
    s = (User.update({
        User.profile_picture: file.filename
    }).where(User.id == id))
    s.execute()
    s3.upload_fileobj(file,
                      "nextagramtao",
                      file.filename,
                      ExtraArgs={
                          "ACL": "public-read",
                          "ContentType": file.content_type
                      })
    return redirect(url_for('users.show', name=current_user.name))
Example #5
0
def upload_file_to_s3(file, fileName, fileContentType, bucket_name, s3id, acl="public-read"):
    # Docs: http://boto3.readthedocs.io/en/latest/guide/s3.html
    try:
        s3.upload_fileobj(
            file,
            bucket_name,
            s3id,
            ExtraArgs={
                "ACL": acl,
                "ContentType" : fileContentType
            }
        )
    except Exception as e:
        print("Something Happened: ", e)
        return e
    return "{}{}".format(S3_LOCATION, s3id)
Example #6
0
def upload_profile():
    file = request.files['image']
    bucket_name = "nextagram-aws-bucket"
    s3.upload_fileobj(file,
                      bucket_name,
                      file.filename,
                      ExtraArgs={
                          "ACL": "public-read",
                          "ContentType": file.content_type
                      })
    identity = get_jwt_identity()
    user = User.get(username=identity)
    user.profile_image = f"https://{bucket_name}.s3-ap-southeast-1.amazonaws.com/{file.filename}"
    if user.save():
        return jsonify({'message': 'success'})
    else:
        return jsonify({'errors': user.errors})
def upload_file_to_s3(acl="public-read", **kwargs):
    file = kwargs.get('file')
    try:
        s3.upload_fileobj(
            file,
            S3_BUCKET,
            kwargs.get('folder') + file.filename,
            ExtraArgs={
                "ACL": acl,
                "ContentType": file.content_type
            }
        )
        flash('Image successfully uploaded', 'success')

    except Exception as e:
        # This is a catch all exception, edit this part to fit your needs.
        flash("Something Happened: ", e)
        return e
Example #8
0
def upload_file_to_s3(file, bucket_name, acl="public-read"):
    """
    Docs: http://boto3.readthedocs.io/en/latest/guide/s3.html
    """

    try:
        s3.upload_fileobj(file,
                          bucket_name,
                          file.filename,
                          ExtraArgs={
                              "ACL": acl,
                              "ContentType": file.content_type
                          })

    except Exception as e:
        print("Something Happened: ", e)
        return e

    # return "{}{}".format(app.config["S3_LOCATION"], file.filename)
    return "{}{}".format(S3_LOCATION, file.filename)
Example #9
0
def upload():
    # breakpoint()
    try:
        file = request.files.get("user_file")
        s3.upload_fileobj(file, S3_BUCKET, file.filename)
        flash("successfully updated")
        file = request.files.get("user_file")
        u = (User.update({User.picture: file.filename
                          })).where(User.username == current_user.username)
        # userp = current_user.picture = request.files.get("user_file").filename
        # userp.save()
        u.execute()
        return redirect(
            url_for("users.edit",
                    img=current_user.profile_image_url,
                    id=current_user.id))
    except:
        flash("Something went wrong!!")
        return render_template("users/edit.html",
                               img=current_user.profile_image_url,
                               id=current_user.id)