3

compress.html

 <form action="/compress" method="POST"  enctype="multipart/form-data">
            {% csrf_token %}
            <label for="pdf">Select pdf :</label>
            <input type="file" name="pdf1" id ="pdf1" accept="pdf/*" />
            <br>
            <button type="submit" class="btn btn-dark mt-2"  value="click">
             submit
            </button>
            <script type="text/javascript">
            function getFilePath(){
            $('input[type=file]').change(function () {
            var filePath=$('#fileUpload').val(); 
             });
             }
            </script>

views.py

  def mergepdf(request):
    from pylovepdf.ilovepdf import ILovePdf
    ilovepdf = ILovePdf('my_secrete_key', verify_ssl=True)
    task = ilovepdf.new_task('compress')
    task.request.FILES['full_path']# here i want full path of selected file 
    task.set_output_folder('/Downloads/download_pdffile')
    task.execute()
    task.download()
    task.delete_current_task()

The filePath var contains the only name of selected file, not the full path. I searched it on the net, but it seems that for security reasons browsers (FF, chrome) just give the name of the file. Is there any other way to get the full path of the selected file?

  • 1
    Javascript will indeed not give you the full path, since it's on the client side. You don't need it there. You need the path to the PDF file in your views.py. Concatenate the filename with the path where the file will be uploaded to. – webtweakers Apr 27 '20 at 15:25

0 Answers0