-
Notifications
You must be signed in to change notification settings - Fork 14
[FEEDS-1206]fix file uploads #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3b33759
c0452a3
6de7e2c
c927b2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,15 @@ | ||
| import json | ||
| from typing import List, Optional | ||
|
|
||
| from getstream.common import telemetry | ||
| from getstream.common.async_rest_client import CommonRestClient | ||
| from getstream.models import ( | ||
| FileUploadResponse, | ||
| ImageSize, | ||
| ImageUploadResponse, | ||
| OnlyUserID, | ||
| ) | ||
| from getstream.stream_response import StreamResponse | ||
|
|
||
|
|
||
| class CommonClient(CommonRestClient): | ||
|
|
@@ -10,3 +21,38 @@ def __init__(self, api_key: str, base_url, token, timeout, user_agent=None): | |
| timeout=timeout, | ||
| user_agent=user_agent, | ||
| ) | ||
|
|
||
| @telemetry.operation_name("getstream.api.common.upload_file") | ||
| async def upload_file( | ||
| self, file: Optional[str] = None, user: Optional[OnlyUserID] = None | ||
| ) -> StreamResponse[FileUploadResponse]: | ||
| form_fields = [] | ||
| if user is not None: | ||
| form_fields.append(("user", json.dumps(user.to_dict()))) | ||
| return await self._upload_multipart( | ||
| "/api/v2/uploads/file", | ||
| FileUploadResponse, | ||
| file, | ||
| form_fields=form_fields, | ||
| ) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| @telemetry.operation_name("getstream.api.common.upload_image") | ||
| async def upload_image( | ||
| self, | ||
| file: Optional[str] = None, | ||
| upload_sizes: Optional[List[ImageSize]] = None, | ||
| user: Optional[OnlyUserID] = None, | ||
| ) -> StreamResponse[ImageUploadResponse]: | ||
| form_fields = [] | ||
| if user is not None: | ||
| form_fields.append(("user", json.dumps(user.to_dict()))) | ||
| if upload_sizes is not None: | ||
| form_fields.append( | ||
| ("upload_sizes", json.dumps([s.to_dict() for s in upload_sizes])) | ||
| ) | ||
| return await self._upload_multipart( | ||
| "/api/v2/uploads/image", | ||
| ImageUploadResponse, | ||
| file, | ||
| form_fields=form_fields, | ||
| ) | ||
|
Comment on lines
+40
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same type issue for Proposed fix `@telemetry.operation_name`("getstream.api.common.upload_image")
async def upload_image(
self,
- file: Optional[str] = None,
+ file: str,
upload_sizes: Optional[List[ImageSize]] = None,
user: Optional[OnlyUserID] = None,
) -> StreamResponse[ImageUploadResponse]:🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,15 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import List, Optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from getstream.common import telemetry | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from getstream.common.rest_client import CommonRestClient | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from getstream.models import ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FileUploadResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ImageSize, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ImageUploadResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| OnlyUserID, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from getstream.stream_response import StreamResponse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class CommonClient(CommonRestClient): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -10,3 +21,38 @@ def __init__(self, api_key: str, base_url, token, timeout, user_agent=None): | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| timeout=timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user_agent=user_agent, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @telemetry.operation_name("getstream.api.common.upload_file") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def upload_file( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, file: Optional[str] = None, user: Optional[OnlyUserID] = None | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> StreamResponse[FileUploadResponse]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form_fields = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if user is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form_fields.append(("user", json.dumps(user.to_dict()))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return self._upload_multipart( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "/api/v2/uploads/file", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FileUploadResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form_fields=form_fields, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @telemetry.operation_name("getstream.api.common.upload_image") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def upload_image( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| self, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file: Optional[str] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| upload_sizes: Optional[List[ImageSize]] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| user: Optional[OnlyUserID] = None, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) -> StreamResponse[ImageUploadResponse]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form_fields = [] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if user is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form_fields.append(("user", json.dumps(user.to_dict()))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if upload_sizes is not None: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form_fields.append( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ("upload_sizes", json.dumps([s.to_dict() for s in upload_sizes])) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return self._upload_multipart( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "/api/v2/uploads/image", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ImageUploadResponse, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| file, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form_fields=form_fields, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same type mismatch applies to The Proposed fix `@telemetry.operation_name`("getstream.api.common.upload_image")
def upload_image(
self,
- file: Optional[str] = None,
+ file: str,
upload_sizes: Optional[List[ImageSize]] = None,
user: Optional[OnlyUserID] = None,
) -> StreamResponse[ImageUploadResponse]:📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.