My code is working as expected, but i would like to make some changes and I don't want to save the uploaded filename in SQLite database.
My code:
# false commit to get upload file name
upload = form.save(commit=False)
upload.save()
uploadFile = upload.file.name.split('/')[-1]
As I said, I don't want to save this form in database. So i comment out the line upload.save()
, but the code is not working, displaying the below error message:
Exception Type: com_error
Exception Value: it's possible that the file may be removed, renamed or trashed.
Thank you!
CodePudding user response:
if you just want the uploaded filename in your view then you can get it from request object directly like below:-
for filename, file in request.FILES.iteritems():
name = request.FILES[filename].name