how to get browsed file location by user when he wants to download a file - playframework-2.3

this is my html code to make user to download a file and it is hitting controller
window.location.href="#routes.ListManagementController.downloadList("+listName+")?listname="+listName;
this is my controller code:
String listName = Form.form().bindFromRequest().get("listname");
response().setContentType("application/x-download");
response().setHeader("Content-disposition", "attachment;filename="+listName+"_data_export.csv");
The above two respose() statements make a pop up to download a file I want the browsed file location
File file = new File("C:/csv/" + filename);
So, using servlet api we can write the content into browsed file location using respose.getOutputStream() method. In play there are is no support for servlet. I want browsed file location selected by user so that i can give that location to File and write the file over there.

You can't get the location of a directory on the client, and even if you could, your server side could wouldn't be able to write to it (since it would usually be on a different computer).

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).

UWP - How to read .jpg from Desktop inside of app

The functionality I am needing for my app is that if a user copies an image file (for example, a .jpg file in their Desktop folder), I need to extract that file from the clipboard and display it in my app.
I can already extract the storage file from the clipboard, and get the file path. But when I try to read the file path into a BitmapImage, I received a System.UnauthorizedAccessException error, because the image is not located in the app's folder.
It sounds like you are trying to open the file by path rather than directly using the StorageFile returned by the file picker.
Your app doesn't have direct access to most of the file system (including the downloads directories) and can access such files only indirectly via the file system broker. The StorageFile object works with the broker to open files the use had authorized and provides a stream of the files contents for the app to read and write to.
You can use Xamarin.Plugin.FilePicker or FilePicker-Plugin-for-Xamarin-and-Windows .
You may x:Bind path to XAML Image
<Image>
<Image.Source>
<BitmapImage UriSource="{x:Bind GetAbsoluteUri(Path)}"/>
</Image.Source>
</Image>
Code behind:
private Uri GetAbsoluteUri(string path)
{
return new Uri(Path.GetFullPath(path), UriKind.Absolute);
}
Try, hope it'll work :)

get full path of selected(browsed) file jsp web

How can I get full path of selected file.
for example I selected logo.png
it should get c:\user\admin\desktop\logo.png
String im = request.getParameter("image");
InputStream inputStream = new FileInputStream(new File(im));
pstmt=con.prepareStatement("Insert into items(image) values(?)");
pstmt.setBlob(1, inputStream);
This code insert to datbase it show this following error
java.io.FileNotFoundException: logo.png (The system cannot find the file specified)
(tried everything no luck)
If you are trying to do file upload to a database using JSP and Servlet the way you are doing is wrong.
You cannot get the file path from a client machine for security reasons. Even if you get the file path from client machine that file won't be available in the server, since the code runs in the server you will allways get java.io.FileNotFoundException.
Check Upload files to database (Servlet + JSP + MySQL) example for how to upload a file to MySQL database using JSP and Servlet.

Referring to a file with partially known name in html

I am making a webpage. I have to give link of a log file which is present on the server but that file is generated with a random number at the end.
I know the starting part of the filename. Here is my code -
Download log file Here
for example the name of the file is "log_parser2088.log" this 2088 number is randomly generated everytime the code runs and there is only one file in that folder which starts with the name "log_parser". I want to give reference to this file but this is not working.
HTML doesn't support this kind of references. Use PHP or ASP.NET for this task since these server side programms have access to the servers file system and can, f.e., read every filename in a directory.
Example for PHP:
// path to your log file directory
$directoryPath = "\\home\\logs\\";
// read all files from that directory
$files = scandir($directoryPath);
// print download link
foreach($path in $files)
echo("Download");

How to get a directory path from the client using html form

I am developing some web app to be used on my local pc only.
The question is that I want to be able to browse to some directory or file and get its path. So is this possible using some file/directory path picker (not the whole dir, just its path).
I don't want to manually type the path in the text input, rather to have some visualized way to navigate to the dir.
Thanks
Previous Removed
EDITED:
$("#someFileUpload").change(InputChanged);
function InputChanged(e){
var fileList = e.target.files;
//You now have a list of the files uploaded, from here you can work with the objects..
}