Skip to content

Conversation

@prchaudh
Copy link

@prchaudh prchaudh commented Dec 8, 2022

No description provided.

Creates community attachment entry
"""
url = '{0}{1}v1/communities/{2}/attachments'.format(self.endpoint, self.IGLOO_API_ROOT_V2, communityKey)
Copy link
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.

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
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

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("communityKey", help="Community Key")
parser.add_argument("userid", help="User ID")
Copy link
Owner

Choose a reason for hiding this comment

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

User UUID? Namespace?


if args.contentType not in allowedContentType:
print("Allowed contentTypes "+str(" ".joing(allowedContentType))
return
Copy link
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?



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
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.

result = self.igloo.post(url, data=payload)
return result.headers['Location']

def send_image_to_url(self, url, image, headers):
Copy link
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

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
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