Draft
Conversation
xkahn
reviewed
Dec 9, 2022
pyigloo/__init__.py
Outdated
|
|
||
| Creates community attachment entry | ||
| """ | ||
| url = '{0}{1}v1/communities/{2}/attachments'.format(self.endpoint, self.IGLOO_API_ROOT_V2, communityKey) |
Owner
There was a problem hiding this comment.
You should use the self.communitykey value instead of passing it to the routine.
You can see an example of this:
- getting called: https://github.com/xkahn/pyigloo/blob/main/tests/getSpaceGroups.py#L45
- being used in a library routine: https://github.com/xkahn/pyigloo/blob/main/pyigloo/__init__.py#L394
This allows us to not pass the value around. Also, a single Igloo session should keep the same community key the whole session.
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") |
Owner
There was a problem hiding this comment.
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
tests/uploadUserProfilePic.py
Outdated
| import argparse | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("communityKey", help="Community Key") | ||
| parser.add_argument("userid", help="User ID") |
tests/uploadUserProfilePic.py
Outdated
|
|
||
| if args.contentType not in allowedContentType: | ||
| print("Allowed contentTypes "+str(" ".joing(allowedContentType)) | ||
| return |
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 |
pyigloo/__init__.py
Outdated
| result = self.igloo.post(url, data=payload) | ||
| return result.headers['Location'] | ||
|
|
||
| def send_image_to_url(self, url, image, headers): |
Owner
There was a problem hiding this comment.
don't pass headers. Should calculate them in this function
| Uploads attachment to entry provided from previous call | ||
| """ | ||
| url = '{0}{1}'.format(self.endpoint, url) | ||
| result = self.igloo.patch(url, headers=headers, data=image) |
Owner
There was a problem hiding this comment.
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
)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.