I am looking to attach a file to an email which includes all the content a user inputs from a contact form. I currently refer a PDF which records their inputs, and I attach that PDF from a file destination. However, I do not know how to attach additional files which the user provides on the contact form. In this case, this is represented by "msg.attach\_file(upload\_file)." My thoughts are:

1. Have the file be uploaded to a destination; however, it needs to renamed to a uniform name each time so I can refer to it during the attachment process (msg.attach\_file).
2. Figure out a way to use request.FILES to attach it immediately without having to worry about its file name or upload destination (I am not sure if msg.attach\_file is a valid command for this method).

Is there a right way to perform this action? I am attempting to perform **method 2** with my **views.py** file which refers to my forms.py file, but it is giving me an error.

**Views.py**

```
def quote_req(request):
submitted = False
if request.method == 'POST':
    form = QuoteForm(request.POST, request.FILES)
    company = request.POST['company']
    contact_person = request.POST['contact_person']
    upload_file = request.FILES['upload_file']
    description = 'You have received a sales contact form'
    if form.is_valid():
        data_dict = {
            'company_': str(company),
            'contact_person_': str(contact_person),
            }
        write_fillable_pdf(INVOICE_TEMPLATE_PATH, INVOICE_OUTPUT_PATH, data_dict)
        form.save()
        # assert false
        msg = EmailMessage('Contact Form', description, settings.EMAIL_HOST_USER, ['sample@mail.com'])
        msg.attach_file('/uploads/file.pdf')
        msg.attach_file(upload_file)
        msg.send(fail_silently=False)
        return HttpResponseRedirect('/quote/?submitted=True')
else:
    form = QuoteForm()
    if 'submitted' in request.GET:
        submitted = True

```

---

**Error Log**

```
TypeError at /quote/

expected str, bytes or os.PathLike object, not InMemoryUploadedFile

Request Method:     POST
Request URL:    http://www.mytestingwebsitesample.com/quote/
Django Version:     2.1.3
Exception Type:     TypeError
Exception Value:    

expected str, bytes or os.PathLike object, not InMemoryUploadedFile

```