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

Cannot add multiple files with the same name within multipart request #270

Open
ghandic opened this issue Apr 25, 2022 · 2 comments
Open

Comments

@ghandic
Copy link

ghandic commented Apr 25, 2022

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='foo@example.com' \
    -F cc='bar@example.com' \
    -F bcc='baz@example.com' \
    -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, 'foo@example.com')),
    ('cc', (None, 'bar@example.com')),
    ('bcc', (None, 'baz@example.com')),
    ('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

@allanlewis
Copy link

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

@ghandic
Copy link
Author

ghandic commented Jan 8, 2023

Why suggestions on how that can be fixed? Happy to look just need pointing in the direction to save time @prkumar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants