Skip to content
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

[ISSUE-3636] Add attachment uploading #222

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion djautotask/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
VERSION = (1, 6, 1, 'final')
VERSION = (1, 6, 2, 'final')

# pragma: no cover
if VERSION[-1] != "final":
Expand Down
22 changes: 21 additions & 1 deletion djautotask/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.core.cache import cache
from django.db import models
from django.utils import timezone
from djautotask.utils import DjautotaskSettings
from djautotask.utils import DjautotaskSettings, encode_file_to_base64
from retrying import retry

RETRY_WAIT_EXPONENTIAL_MULTAPPLIER = 1000 # Initial number of milliseconds to
Expand Down Expand Up @@ -973,6 +973,26 @@ def document_download(self, object_id, document_id, record_type):
self._log_failed(response)
return None

def upload_attachments(self, object_id, file, recordType):
ENDPOINT_DOCUMENTS = f'{recordType}/{object_id}/Attachments'
endpoint_url = f'{self.api_base_url}/{ENDPOINT_DOCUMENTS}'

file_name, file_content = file['file']
file_data = encode_file_to_base64(file_content)

body = {
"id": 0,
"attachmentType": "FILE_ATTACHMENT",
"fullPath": file_name,
"publish": 1,
"title": file_name,
"data": file_data
}

response = self.request('POST', endpoint_url, body)

return response

def get_attachment(self, object_id, document_id, record_type):
return self.document_download(object_id, document_id, record_type)

Expand Down
5 changes: 5 additions & 0 deletions djautotask/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
from django.conf import settings


Expand All @@ -17,3 +18,7 @@ def get_settings(self):
request_settings.update(settings.DJAUTOTASK_CONF_CALLABLE())

return request_settings


def encode_file_to_base64(file_content):
return base64.b64encode(file_content.read()).decode('utf-8')
Loading