Select folder in directory in input

Asked

Viewed 646 times

0

I need to put a input where the user selects the folder he wants to save the notes, but only select.

I tried to do it this way:

 <input asp-for="Caminho" class="form-control" type="file" multiple webkitdirectory id="pasta">

But he shows up to do upload And when I do so:

<input asp-for="Caminho" class="form-control" type="file" id="pasta">

It appears to select a file, not a folder. Is there any way I can select the folder and get the way ?

EDIT

I just need to select the folder, only to make it easy for the user, so it doesn’t need to type the path in hand. Some way to do it?

  • I cannot give an Agra answer... but see here: https://stackoverflow.com/questions/12942436/how-to-get-folder-directory-from-html-type-file-or-any-other-way

  • @Barbetta of this link you gave me I tried, but he tells me to upload, not select the folder. I just wanted to select the folder, so that the user does not need to type, selecting this way, becomes more dynamic.

2 answers

1

Unable to select a website folder using HTML native + JS. You can only select a file or list of files to upload, but not a folder itself.

Usually you won’t even be able to see the original file path that was uploaded, and you simply can’t get direct access to the user’s file system.

Web communication is based on requests HTTP and is stateless, therefore, there would be no way for the server to access the folder on the user’s (remote) PC. And for security reasons, not even the JavaScript the customer can do it.

User can leave folder downloadsconfigured by default in most browsers today.

  • Is there any way to take a path dynamically then ? Because the folder will be used in another function, saving files, which already works, but wanted this folder to be configurable.

  • The file will be saved to the server itself where the application is running or to the client?

  • In the aware itself.

  • So no. Your HTML cannot access the client’s computer

  • @marianac_costa understand that the client may have ordered, but if it is a web application the browser has control of where the download will be saved and the user can choose/ configure as I have already reported in the reply and as Victor Laio has already reported here in his too. In this case it is not better to align the conversation with the client and explain that there is a technical impediment and that this request can leave the tool insecure or buggy?

0

This is not possible with HTML or Javascript due to security issues.

There are solutions that try to implement this in browsers but that do not work well in all browsers, not being at all feasible.

I also don’t see much point in it, because if you want to "save some file" the browsers already make available the download folder that can be configured by the user.

  • I just need to save the path, so when it comes to generating an NFE it knows where to save, and for the user, it becomes more dynamic. I just want to save the way.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.