Skip to content

updated test and methods#2

Draft
prchaudh wants to merge 3 commits into
xkahn:mainfrom
prchaudh:upload-profile-pic
Draft

updated test and methods#2
prchaudh wants to merge 3 commits into
xkahn:mainfrom
prchaudh:upload-profile-pic

Conversation

@prchaudh
Copy link
Copy Markdown

@prchaudh prchaudh commented Dec 8, 2022

No description provided.

Comment thread pyigloo/__init__.py Outdated

Creates community attachment entry
"""
url = '{0}{1}v1/communities/{2}/attachments'.format(self.endpoint, self.IGLOO_API_ROOT_V2, communityKey)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use the self.communitykey value instead of passing it to the routine.
You can see an example of this:

This allows us to not pass the value around. Also, a single Igloo session should keep the same community key the whole session.

Comment thread tests/uploadUserProfilePic.py Outdated
parser.add_argument("communityKey", help="Community Key")
parser.add_argument("userid", help="User ID")
parser.add_argument("image", help="Path to the image")
parser.add_argument("contentType", help="Content Type of the image")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to allow passing this, but if not specified, it should get detected by:
magic.detect_from_filename("/path/to/file").mime_type
from the "magic" library

Comment thread tests/uploadUserProfilePic.py Outdated
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("communityKey", help="Community Key")
parser.add_argument("userid", help="User ID")
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User UUID? Namespace?

Comment thread tests/uploadUserProfilePic.py Outdated

if args.contentType not in allowedContentType:
print("Allowed contentTypes "+str(" ".joing(allowedContentType))
return
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should exit with an error code?

Comment thread tests/uploadUserProfilePic.py Outdated


image = pathlib.Path(args.image).read_bytes()
update_profile_picture(self, args.communityKey, args.userId, image, args.contentType) No newline at end of file
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe pass the filename here.

Comment thread pyigloo/__init__.py Outdated
result = self.igloo.post(url, data=payload)
return result.headers['Location']

def send_image_to_url(self, url, image, headers):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't pass headers. Should calculate them in this function

Comment thread pyigloo/__init__.py
Uploads attachment to entry provided from previous call
"""
url = '{0}{1}'.format(self.endpoint, url)
result = self.igloo.patch(url, headers=headers, data=image)
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        file_size = os.path.getsize(file_path)
        headers = {
            "Content-Length": f"\"{file_size}\"",
            "Content-Range": f"bytes 0-{file_size-1}/{file_size}"
        }
        response = requests.put(
            url, open(file_path, "rb"), headers=headers
        )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants