Home:ALL Converter>Django - Upload PDF and Excel file to mysql database

Django - Upload PDF and Excel file to mysql database

Ask Time:2018-08-15T02:13:33         Author:Sainath

Json Formatter

I have written a code to upload an excel sheet and save the contents to mysql database. Below is the code to upload the file in memory.

form = UploadFileForm(request.POST,request.FILES)
if form.is_valid():
    file_in_memory = request.FILES['file'].read()
    wb = load_workbook(filename=BytesIO(file_in_memory), data_only=True)

Now, I want to upload a PDF file and save the path to mysql database using the same function. For instance, If excel has record A then there is an associated PDF file which I have to link. How do I handle this situation? Using formset is a solution? I am aware of multi-file upload but I assume that will save the file path to the database directly.

Author:Sainath,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/51847497/django-upload-pdf-and-excel-file-to-mysql-database
yy