I have a exe file I want to download, using a url.
I'm using the File class and calling the download(url) function to download the file.
This lets me choose a place to download the file, but the default is either the path of the application directory or the last place the user choose to save a file. This sometimes causes problems because the user will try to save it to their application directory, but we don't allow them to have write access to the folder.
I want to be able to set the default to somewhere like the downloads folder. Is there a work around to achieve this?
update: Actually i found the answer. you just place the path in the file creation. var file:File = new File("path");
I'm guessing you meant to ask about the FileReference class because the File class doesn't have a download function.
From the asdoc on FileReference:
The FileReference and FileReferenceList classes do not let you set the default file location for the dialog box that the browse() or download() methods generate
Related
I have a JavaFX program in which the user may choose a profile picture. This profile picture is applied and should then be saved to a resources folder at the same level as my bin and src folders. I have a few questions:
How do you define the file path? This is my current attempt. I get a NullPointerException, but I think that has something to do with the output stream. It's fixable, so I am mostly worried about the path. This works when accessing an image, so why doesn't it work when saving one?
// Store chosen profile picture
File outputFile = new File("/resources/profilePicture.png");
ImageIO.write(SwingFXUtils.fromFXImage(croppedProfilePicture, null), "png", outputFile);
When I go to deploy the application, will I get issues with saving to a resource folder at the same level as bin and src? Do bin and src even exist when you deploy an application?
Thanks. I can supply any more information if needed.
I'm trying to get the relative path to a file inside a app/cache dir.
I've tried via custom config file using:
parameters:
output_dat_path : %kernel.root_dir%/cache/%kernel.environment%/myfile.dat
Also I tried:
$kernel = $this->get('kernel');
$path = $kernel->getRootDir() . '/cache/' . $kernel->getEnvironment() . 'myfile.dat';
Both ways generate absolute paths, that both work fine using them inside a controller or service, but, I need a relative path to generate a link for the user.
I'm thinking to move the file to the web directory in my service and use asset in the template to generate the link, but the file is private for every user and I don't want to expose it.
Any thought?
Thanks in advance.
UPDATE
I solved this as follows:
User, once authenticated, generates his file. If the file doesn't exists, is generated. If it exists, the controller checks the user rights, time, etc. and returns the file.
If the system has to be generated, the file is created in a private folder and an encrypted name is generated. The encrypted name is generated using base_64 and some changes after that.
The system shows to the user a link. That link is something like /get/privatefile/eDfa...23Hn
When the user clicks on it, the controller checks the user, time from creation, etc.
If all is fine the controller returns the file.
I made this because the file must be created once, and be available for a short period of time and after must be deleted. If an user pass the link to other person, the checksum of the encrypted name fails and the file cannot be accessed.
I am sure that this is not the best solution but it works right know.
Assume I want to write to a new file created within the space of my webapp.
One way would be use getServletContext().getRealPath("/") and use that String to create a new file on the server. However, often I come across advice like not using getServletContext().getRealPath("/").
Can someone please let me know of another way to write a new file within my webapp?
Many thanks.
Have some configuration property containing the absolute path of a directory outside of the webapp and web server path, read this path from the configuration property, and write to this directory.
To serve files from this directory, write a servlet that takes the name or ID of this file as parameter, reads the file from the directory, and sends its content to the response.
This will
work even if the app is deployed as a war file and never unzipped to the file system
allow you to redeploy the next version of the app or server without deleting all the uploaded/created files
allow you to add whatever control you want on the uploaded/created files, instead of making them available to everyone
In short, treat these files as data, stored in a database which happens to be the file system instead of a SQL database.
Is there a way to get the select file dialog box open and putting the location of the file into a textbox without ever uploading the file?
ETA I'm using VB.NET in a web page. By using the asp:fileupload tag I can get the file location
_fudFileLocation.PostedFile.FileName_
But how do I prevent the file from being uploaded at all. We don't need it, just the file location. (The files are on a shared drive so if it's M:\documents\todayslunch.pdf for person A, it's the same for person B.)
You do not get access to the full filepath in the browser because of security.
If this was possible, one could get the full layout of the computer of anyone going to any website.
System.Web.HttpPostedFile.FileName gets the fully qualified name of the file on the client which includes the directory path.
In flex 3 web application how to set default save location for images?
Thanks.
From the FileReference documentation:
The FileReference and FileReferenceList classes do not let you set the default file location for the dialog box that the browse() or download() methods generate. The default location shown in the dialog box is the most recently browsed folder, if that location can be determined, or the desktop. The classes do not allow you to read from or write to the transferred file. They do not allow the SWF file that initiated the upload or download to access the uploaded or downloaded file or the file's location on the user's disk.
If you're using AIR, you have more control using the File class.