Add support to override attachment file name
See original GitHub issueWithin 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:
- Created 6 years ago
- Reactions:2
- Comments:5
Top GitHub Comments
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!
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:
data
can be a Buffer, a Stream, or a string representing a path to a file.