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

Auto-determine the mimetype on a attachment #967

Open
jiska78 opened this issue Jan 19, 2021 · 1 comment
Open

Auto-determine the mimetype on a attachment #967

jiska78 opened this issue Jan 19, 2021 · 1 comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@jiska78
Copy link

jiska78 commented Jan 19, 2021

I'm using SendGrid on my website and it allows a user to attach a file to an email. I used to just have the code $email->addattachment($filename) which no longer works on the new version of SendGrid. The new format is this:

    $attachment = new Attachment();
    $attachment->setContent("xxxx");
    $attachment->setType("application/pdf");
    $attachment->setFilename("balance_001.pdf");
    $attachment->setDisposition("attachment");
    $attachment->setContentId("Balance Sheet");
    $mail->addAttachment($attachment);

My problem with that is, how am I possibly going to know what filetype the user uploads. It could be anything? Can't I just tell sendgrid to attach whatever file is uploaded to the email being sent?

@thinkingserious thinkingserious changed the title Attaching a file Auto-determine the mimetype on a attachment Jan 19, 2021
@thinkingserious thinkingserious added status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap labels Jan 19, 2021
@thinkingserious
Copy link
Contributor

Hello @jiska78,

Currently, we have not implemented mime-type detection in this version of the helper library. A workaround would be to utilize the mimetypes module, specifically mimetypes.guess_type (reference).

I suggest we add a mimetype function to determine the mimetype and then optionally call it within the file_name function. To make this a non-breaking change, we can add a second parameter to file_name that defaults to false.

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog. I will update the title for this issue accordingly.

With best regards,

Elmer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

No branches or pull requests

2 participants