I am using Django to build a webapp that will only be used locally. Before this I had very little direct experience with web development, Django and HTML.
I would like the user to be able to browse for files on his/her own machine, as is possible with <input type="file" [...]>
. However, since the app will only be used locally and since some very large files will be involved, I only want access to the filepath - i.e. without uploading the file data itself - upon pressing submit.
Using Django's FileField class I was unable to bypass the file upload phase. I used custom upload filters (and confirmed that they were actually called), and tried raise SkipFile
in a few different spots in them which is supposed to cancel uploading the file according to the documentation - as I understood it, at least.
I thought I'd cracked it by entering the HTML directly instead of using my dir_form
from Django:
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<!-- {{ dir_form }} -->
<input type="file" id="docpicker" name="filepath">
<input type="submit" value="Submit" name="file">
</form>
and I tried raise SkipFile
at different points in the upload handler (the prints were to see in what order they were called):
class SkippingUploadHandler(FileUploadHandler):
def handle_raw_input(self, input_data, META, content_length, boundary, encoding=None):
print(1)
raise SkipFile
def new_file(self, *args, **kwargs):
print(2)
raise SkipFile
def receive_data_chunk(self, raw_data, start):
print(3)
raise SkipFile
but these didn't help.
I would like the user to be able to browse in his/her own system, choose a file and press 'Submit'. On submitting, I would like only the filepath to be transferred and not the file contents, as is currently the case.
All help (and patience) greatly appreciated!