I tried the following: def myhandle_uploaded_file(f): with open('some/file/name.txt', 'wb+') as destination: for chunk in f.chunks(): destination.write(chunk)
def SendPrescriptionbyMail(request, cliniclabel, patient_id): patient_id = int(patient_id) if request.method == 'POST': form = UploadFileForm(request.POST, request.FILES) if form.is_valid(): myhandle_uploaded_file(request.FILES['file']) return HttpResponseRedirect('/success/url/') But I got the following error, which I cant make heads or tails of: 2018-11-14 15:16:49,585 django.request ERROR Internal Server Error: /clinic/madhav/prescription/sendemail/patient/18 Traceback (most recent call last): File "/home/joel/myappointments/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/joel/myappointments/venv/lib/python3.6/site-packages/django/utils/deprecation.py", line 93, in __call__ response = self.process_response(request, response) File "/home/joel/myappointments/venv/lib/python3.6/site-packages/django/middleware/common.py", line 105, in process_response if response.status_code == 404: AttributeError: 'str' object has no attribute 'status_code' Sincerely yours, Joel G Mathew On Wed, 14 Nov 2018 at 14:45, Joel Mathew <j...@joel.su> wrote: > > I use jspdf to generate pdf for downloading by end users. I wish to > add a function to let them send an email to themselves through the > server. > Reading a little bit, I've seen a method to send the pdf to the server > as a base encoded string, and then have the server decode it, before > emailing the object. It seems to be bad practise and a convoluted way, > to me. > > Anyway, the javascript is doing this: > > var pdf = doc.output(); > cliniclabel = $("#TopPatientBar").data("cliniclabel") > patient_id = $('body').find("#PatientIP").html(); > $.ajax({ > method: "POST", > url: > `/clinic/${cliniclabel}/prescription/sendemail/patient/${patient_id}`, > data: {data: pdf}, > }).done(function(data){ > console.log(data); > }); > > And as a preliminary step, I'm trying to read the POST data: > > def SendPrescriptionbyMail(request, cliniclabel, patient_id): > patient_id = int(patient_id) > if request.method == 'POST': > print("POST data", request.POST) > cus = customer.objects.get(cstid = patient_id) > recipient=cus.email > > But I got this: > [14/Nov/2018 14:39:27] "GET > /appointments/static/appointments/js/popper.min.js.map HTTP/1.1" 404 > 1749 > [14/Nov/2018 14:39:30] "GET /clinic/medicines HTTP/1.1" 200 8389 > 2018-11-14 14:39:36,360 django.security.RequestDataTooBig ERROR > Request body exceeded settings.DATA_UPLOAD_MAX_MEMORY_SIZE. > 2018-11-14 14:39:36,441 django.request WARNING Bad Request: > /clinic/madhav/prescription/sendemail/patient/18 > [14/Nov/2018 14:39:36] "POST > /clinic/madhav/prescription/sendemail/patient/18 HTTP/1.1" 400 17930 > > But rather than create an XY problem, can anyone tell me whether I'm > approaching this in the right way? Isnt base encoding a pdf object > from javascript for sending to django the wrong way to do this? > > What would be the right way? Just point me along what I need to be looking at. > > Sincerely yours, > > Joel G Mathew -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA%3Diw_9brsFs0KpQA0oCGg4zia1rYeJXOHz2QeK0%2Bp4rNsdSng%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.