question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support to override attachment file name

See original GitHub issue

Within the file and method request.js -> postMulti we could pass FormData an extra param object, { filename: } that would allow us to override the name of the file(s) attached to the email. This could be handled similar to how the Bojand/Mailgun-JS implementation handles this feature.

i.e.

formData.append(key, $file, { filename: $fileName });

An example use-case for this type of feature would be a similar scenario as noted below

A NodeJS REST API application generates a temporary file(s) need for an emails attachment(s). These files are created with random unique filename(s), basically a hash. To provide a better UX for the end user to know what the attached file(s) are, the hashed names are overridden with a more specific name(s), i.e. lzmLymzKoXZv becomes Order-Invoice.

If we could provide the desired name of the attachment file(s), the scenario above would simplify current business logic. Because the file(s) are generated by an API server, which could have multiple requests hit at once, the logic has to create a unique folder for the generated file(s) to avoid conflicting file names. After the email is sent the folder and file is then removed.

It would be much simpler logic to just remove the file that a handle already exists for in context, instead of having to target the parent folder and remove it. Which also poses it own complexity because the user could of sent another request to the API which generates another file, at which point the folder cannot be removed yet. I understand this is being nit-picky on removing the generated folder(s), but that doesn’t negate the lack of a basic feature of FormData

cited sources noted above: https://github.com/mailgun/mailgun-js/blob/master/lib/request.js#L105 https://github.com/bojand/mailgun-js/blob/master/lib/request.js#L205

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

1reaction
ricardogracacommented, Nov 13, 2019

Ah… indeed it is. So I went through all that trouble and there was a better way to do it 😅

Similarly named packages with equally named repositories are evil!

1reaction
ricardogracacommented, Oct 15, 2019

It’s actually possible to set the filename of attachments currently, but it’s not very straightforward. I had to dig into the source code to figure this out:

const Mailgun = require('mailgun-js')
const Attachment = require('mailgun-js/lib/attachment')
const mailgunClient = new Mailgun(/* config */)

const myAttachment = new Attachment({
  data,
  filename: 'my_file.pdf',
  contentType: 'application/pdf'
})

mailgunClient.messages().send({
  attachment: [myAttachment]
  // rest of message data
})

data can be a Buffer, a Stream, or a string representing a path to a file.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add support to override attachment file name #22 - GitHub
To provide a better UX for the end user to know what the attached file(s) are, the hashed names are overridden with a...
Read more >
Outlook attachments change file name when dragged from ...
When composing an email, click Attach File to add the attachment to see if the name is changed. 2. Please make sure your...
Read more >
How to change the file name in an e-mail attachment - IBM
1. If your file name will be created from concatenated values, it is probably best to get this out of the way. (Should...
Read more >
Change attachment filename - WordPress Stack Exchange
You can set the file name, file types & mime types that you want to change inside the function before the foreach loop....
Read more >
Attachment File Name Changed - Adding a "24" to the file path ...
Attachment File Name Changed - Adding a "24" to the file path name · Save as the activity rule “pyUploadFile” from “Data-WorkAttach-File” class....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found