get full path of selected(browsed) file jsp web - mysql

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.

Related

run-time 2737 when connecting OLE Object (Word file) who is inside OneDrive Folder

I'm developing a solution based on Word and Access.
In an Access mask, the user click a command and a Word file is automacilly created and inserted in a BoundObjectFrame via the following command:
With OleDoc
.Class = "Word.Document"
.OLETypeAllowed = acOLELinked
.SourceDoc = strFullNameFile
.Action = acOLECreateLink
End With
Everything is fine if the file named strFullNameFile is in a normal folder on my computer. But if is in a subfolder inside my OneDrive folder in my computer, I get a
Run-time error 2737
Impossible to find file with OLE object linked...
Do you have any idea why?
Thanks, Lauro
You need to pass the path with subfolder too.
It's searching the file in main folder.

Can't reference json file in root

I created a new Azure WebJobs project which is a console app. I placed a settings.json file in the root and I'm trying to access it using the following code but I keep getting an error that says it cannot locate the file. I think it's looking for it under Debug folder but I don't want to move the file there. How do I reference that file?
var config = new Configuration();
config.AddJsonFile("settings.json");
I tried "~/settings.json" but that didn't work either.
You need to identify if it's a deployment or runtime issue, per this article.
Make sure that your file is in fact getting deployed:
In VS, check that it has Copy to Output directory set to Copy if Newer
Use Kudu Console to look at the relevant WebJob folder under D:\home\site\wwwroot\App_Data\jobs\... and make sure that the json file made it to there next to the exe.
You can try to add your json file into your WebJob project's Resources as shown:
Remember to set the file type as Text and encoding to UTF-8.
In your code, you can easily access your json file as string as below:
// The Resources property depends on your actual file name being referenced
var settingsJson = Resources.settings;
Hope this helps!

neo4j LOAD CSV returns Couldn't Load external resource

Trying CSV import to Neo4j - doesn't seem to be working.
I'm loading a local file using the syntax:
LOAD CSV WITH HEADERS FROM "file:///location/local/my.csv" AS csvDoc
Am wondering if there's something wrong with my CSV file, or if there's some syntax problem here.
If you didn't read the title, the error is:
Couldn't load the external resource at: file:/location/local/my.csv
[Neo.TransientError.Statement.ExternalResourceFailure]
Neo4j seems to need a full path spec to get a file on the local system.
On linux or mac try
LOAD CSV FROM "file:/Users/you/location/local/my.csv"
On windows try
LOAD CSV FROM "file://c:/location/local/my.csv"
.
In the browser interface (Neo4j 3.0.3, MacOS 10.11) it looks like Neo4j prefixes your file path with $path_to_graph_database/import. So you could move your files there. If you are using a command line tool, then see this SO question.
Easy solution:
Once you choose your database location (in my case ReactomeGraphDB60)...
here I placed my ddbb
...go to that folder, and create inside a folder called "import".
Later in the cypher query write (as an example):
LOAD CSV WITH HEADERS FROM "file:///ILClasiffStruct.csv" AS row
CREATE (n:Interleukines)
SET n = row

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

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

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");