uplink
uplink copied to clipboard
Cannot add multiple files with the same name within multipart request
Describe the bug Cannot add multiple files with the same name within multipart request
To Reproduce
An example cURL that works for the api I'm working with is
curl -s --user 'api:YOUR_API_KEY' \
https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages \
-F from='Excited User <YOU@YOUR_DOMAIN_NAME>' \
-F to='[email protected]' \
-F cc='[email protected]' \
-F bcc='[email protected]' \
-F subject='Hello' \
-F text='Testing some Mailgun awesomness!' \
--form-string html='<html>HTML version of the body</html>' \
-F attachment=@files/cartman.jpg \
-F attachment=@files/cartman.png
So attachment needs to be a list of file like objects, converted to raw python requests this would be:
import requests
files = [
('from', (None, 'Excited User <YOU@YOUR_DOMAIN_NAME>')),
('to', (None, '[email protected]')),
('cc', (None, '[email protected]')),
('bcc', (None, '[email protected]')),
('subject', (None, 'Hello')),
('text', (None, 'Testing some Mailgun awesomness!')),
('html', (None, '<html>HTML version of the body</html>')),
('attachment', open('files/cartman.jpg', 'rb')),
('attachment', open('files/cartman.png', 'rb')),
]
response = requests.post('https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/messages', files=files, auth=('api', 'YOUR_API_KEY'))
With uplink, this is not possible as far as I'm aware, requesting to support the following
class Mailgun(Consumer):
"""A Python Client for the Mailgun API."""
@multipart
@post("messages")
def send_email(self, email: Body(type=CreateEmail), attachment: Part = None) -> CreateEmailResponse:
"""Sends an email using mailgun."""
client = Mailgun(base_url=..., auth=('api, ...))
client.send_email(CreateEmail(...), attachment=[open("file-number-1.jpg", "rb"), open("file-number-2.jpg", "rb")])
Expected behavior Allow uploading list of files not just one file
This is frustrating for my use-case because I need to be able to upload tens of files: without this feature I have to make one request per file 😖
I believe requests
supports this, it's just Uplink that doesn't...
Why suggestions on how that can be fixed? Happy to look just need pointing in the direction to save time @prkumar