Select and file input form data in flask - html

So I have this flask website that I can upload files to but I want them to be uploaded into separate folders depending on a drop down list in the same form.
So basically I want it to function that if I pick option "level1" in the form, the file should be uploaded to the level1 subdirectory and if I pick "level2" it should upload to the level2 directory etc.
I started out by adding both the select and input file into the same form but only the file upload is happening and I don't seem to get any value from the select part of the form when printing the details of request.form, request.values, request.data etc.
Likely there is something I am missing with the logic here, perhaps I cannot use select int the same form as file input due to the enctype?
I am not seeing the select part of the form data in the browser either when looping at the dev console.

Related

Save As - html thymeleaf

we need to develop an application similar to the below
On the web page user is asked to select the parameters which are present in a Map<String,Boolean>. Once the user selects his choice of parameters then this Map is saved in a .DAT file. Right now I am saving it in C:/Users/Application. But I want the user to choose which directory he wants to save. I was tempted to use <input type="file".....> but it needs a file in the directory.
Is there any way that the user can specify his own directory where this .DAT file is saved.
Something similar to SaveAs..
A webpage cannot choose where the user will download a file that is returned. For some file types, the browser might even show the file instead of downloading it (e.g. PDF file).

Show previously attached file in HTML form while editing

I am writing a Django application where I have a HTML form to get a few inputs from the user. One of the inputs is an (optional) attachment file. The user is also provided with option to edit the form at some point in future.
When the user chooses to edit the form, the Django view returns the ModelForm and in the template I populate all the fields. But I am not able to populate the attachment in the file input tag. However, I can see that the form object has the attachment in it.
I found a few SO questions which asks for attaching a new file using scripts. And that is not possible due to security reasons. But I am looking for populating the file returned by the server on HTML page.
Is there a way to populate attached files with input tags?
No you can't do that. Instead what you do is provide a link to existing file and a separate input box for a new file in case the user needs it.

Return an uploaded file for resubmission in MVC

My use case is this:
User has a file to upload.
File is validated and various metadata is returned to the user.
User now decides whether to commit the file of not.
Part three is the new bit. Currently the user just uploaded the file, it's committed and information about what happened is returned. I'm having to put in the middle bit.
I've added a boolean supressCommit that allows the file to be uploaded, the information to be gathered but then the committing not to take place.
Now I have a problem, I don't want to introduce state on the server and store the file contents there. That would open up a whole other can of worms. This means that if the user clicks the commit button on the confirmation page I have to upload the file again, this time with suppressCommit set to false.
It's not pretty, but acceptable. My problem is this though, how can I re-upload the original file without the user having to go through selecting the file again?
My options seem to be:
Pass the file contents back in the model.
Not great as now I'll have to somehow put those into the HTTP request manually so they show in the RequestContext in the Request.Files collection.
Pass back the original file path.
If I do this then is it possible to pragmatically set the File input box to something or is that a security violation?

HTML5 drag and drop file, and upload on button click

I have been searching everywhere to find out how to implement the html 5 drag and drop file upload thing and I am still stuck with nothing. I tried BalusC's solution on how to upload the file to a servlet (HTML5 File Upload to Java Servlet). It works just fine, except that I can't send anything else along with the file. What I'm trying to implement is a form which takes both a file and a textual description of what the file is all about, like a "comment". When the user drags and drops the file, enters the comment and clicks "submit", the file must be uploaded to the server, using Servlets. With BalusC's code, the servlet is invoked, but if I try to display the "comment" (which I appended to the formData object), I get a null value. How can I append the comment to the data I send too? I like Vap0r's implementation too (HTML5 drag and drop and multiple file upload), but it doesn't work for me either. Help?

Saving HTML with Checkbox states

I am writing a Perl script that is parsing a file into an HTML table which essentially contains classes and their information. The main objective of the script is for the user to check which classes he needs and the script will read which checkbox states are TRUE and only include those when creating a file that is like the original. Currently, I'm at the point where the HTML file opens in the users default browser, but if I check some of the checkboxes and save the webpage it doesn't save their states (tried it in Chrome and IE). Is there anyway to do this so that when the file is saved the user can hit enter in the program and have it do its conversion?