How can I get the file name from request.FILES in Django?
def upload(request): if request.method == 'POST': form = UploadForm(request.POST, request.FILES) if form.is_valid(): upload = Upload() upload.timestamp = datetime.datetime.now() save_instance(form, upload)
I tried using this but it did not work:
if 'filename' in request.FILES: filename = request.FILES['filename']
Try document. getElementById("FileUpload1"). value this value should have a path for a file to be uploaded, just strip all dirs from that value and you will have file name.
With the file request feature in OneDrive, you can choose a folder where others can upload files using a link that you send them. People you request files from can only upload files; they can't see the content of the folder, edit, delete, or download files, or even see who else has uploaded files.
In order to obtain the Current Working Directory in Python, use the os. getcwd() method. This function of the Python OS module returns the string containing the absolute path to the current working directory.
request.FILES['filename'].name
From the request
documentation.
If you don't know the key, you can iterate over the files:
for filename, file in request.FILES.iteritems(): name = request.FILES[filename].name
file = request.FILES['filename'] file.name # Gives name file.content_type # Gives Content type text/html etc file.size # Gives file's size in byte file.read() # Reads file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With