I’m trying to upload a file with request.FILES and then save not just the file but also when the last time this file was modified on the original machine.
def upload_file(request):
if request.method == "POST" and request.FILES["myfile"]:
myfile = request.FILES["myfile"]
last_modified = myfile.last_modified()
I know this is currently not a method, but is there a way to get the metadata from the uploaded file? I think it’s possible with raw HTML ( File: lastModified property - Web APIs | MDN ) but I’m looking for something more elegant.
The filesystem information about a file is not sent to the server when a file is uploaded. If you want that data, you will need to retrieve it using JavaScript running in the browser to collect that data and then add it to the submitted form.
That event listener that you’ve linked to is an example of getting the data, you could then have a hidden field in the form to have the JavaScript save it in the form to be submitted.