N
Novu14mo ago
aegeavaz

Email attachments

Hi, I'm trying to trigger an event with a file attached and the API is responding with {"statusCode":413,"message":"request entity too large"}. The file is small, its 87Kb. And the length of the json data sent is 132933 (len(json.dumps(data)). This is my python code... Novu v.0.19.0
def send_notification(self, recipient: Recipient, document_name: str, document_file: bytes):
data = {
"name": "notification",
"to": {
"subscriberId": str(recipient.id),
"email": recipient.email,
"firstName": recipient.first_name,
"lastName": recipient.last_name
},
"payload": {
"document":{
"name": document_name,
},
"attachments": [
{
"file": document_file.decode('unicode_escape'),
"name": document_name,
"mime": 'application/octet-stream',
},
],
}

headers = {'Content-Type': 'application/json', 'Authorization': f'ApiKey {settings.NOVU_API_KEY}'}
response = requests.post(url=f"{settings.NOVU_API_URL}/v1/events/trigger", headers=headers, json=data)
def send_notification(self, recipient: Recipient, document_name: str, document_file: bytes):
data = {
"name": "notification",
"to": {
"subscriberId": str(recipient.id),
"email": recipient.email,
"firstName": recipient.first_name,
"lastName": recipient.last_name
},
"payload": {
"document":{
"name": document_name,
},
"attachments": [
{
"file": document_file.decode('unicode_escape'),
"name": document_name,
"mime": 'application/octet-stream',
},
],
}

headers = {'Content-Type': 'application/json', 'Authorization': f'ApiKey {settings.NOVU_API_KEY}'}
response = requests.post(url=f"{settings.NOVU_API_URL}/v1/events/trigger", headers=headers, json=data)
Is there anything I'm missing? Thanks..
6 Replies
aegeavaz
aegeavazOP14mo ago
I think the problem it is not with the API itself, but with the newrelic log.
Gali Baum
Gali Baum14mo ago
@jainpawan21 did you encounter this?
aegeavaz
aegeavazOP14mo ago
I have disabled newrelic log, but still I get error from the API.
Pawan Jain
Pawan Jain14mo ago
Are you sending file as buffer or base64
aegeavaz
aegeavazOP14mo ago
Thanks for the clue Pawan... I was sending a string of the file buffer decoded with unicode_escape encoding, after changing the encoding to base64, it works fine.
Want results from more Discord servers?
Add your server