Folks, here is the situation:
confirmed that the xlsx file is good on the disc.
I copied the file from server and can open without problems.
using FileInputStream and BufferedInputStream to handle the client side download function.
The download function i mean user can download the file by clicking a hyperlink, and a servelet call was made to the java class which uses FileInputStream and BufferedInputStream
Mime type was set correctly as application/vnd.openxmlformats-officedocument.spreadsheetml.shee
After download the file successfully, it will give a "converted failed" error while trying to use office 2003 to open this xlsx file.
any thoughts?
Thanks!
There are bytes which didn't belong in the HTTP response body or were simply missing there.
It's impossible to point out the actual root cause based on the information given as far. You have to check if the right bytes were written from local disk file system to the HTTP response body.
Related
I'm trying to save the edited PDF which I fetched from the remote server back to its location without having it downloaded/stored on the local machine. I'm using JSch SFTP method to get the input PDF file from the SFTP server using
x = new BufferedInputStream(channelSftp.get("example.pdf"));
PDDocument document = PDDocument.load(x);
and after doing some edits using PDFbox, I'm trying to save it using:
documents.save(new File("ftp/path/location"));
I am not able to because I know it only works for your local directory only. Also I can see that document.save accept OutputStream` parameter, but I do not know how to use it here.
I don't have any problems with taking input using stream reader.
All I need is to save that edited PDF back to its location (possibly replace) without having to download it on my local system.
Use the ChannelSftp.put overload that returns OutputStream:
try (OutputStream out = channelSftp.put("example.pdf")) {
documents.save(out);
}
we have a requirement where all file (text , image , PDF etc) uploaded in the Server1. Now we have a Java web application running in a different server (Server 2) which has to read these files and show it in the GUI.
FTP is blocked in web application server. So i am thinking of using HTTP.
The files in Server1 is not distributed .i.e not inside any ear or war.
I managed to get the code to read a file from HTTP.
My question is
- How do i access this file through HTTP when these files are not distributed
- When i write a code accessing the file like http://server1:port1/location of file , its says file not found .
- how do i expose these files , so that i can access it via HTTP from my web application
That means, you want to download the content of the file.
Well at very first, open up a browser. Enter http://server1:port1/FILE_PATH .
what do you get as a response ?
Second, if you get "FILE NOT FOUND" then you need to configure a virtual path mapped to real path in server1. After that, try the URL from browser again. When it works,
URL website = new URL("http://server1/file_location");
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream("file_name");
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
will help you to download the file to your local machine.
My goal is to to convert a .txt file on an FTP page to a simple String for easy manipulation.
The specific .txt file is here: ftp://ftp.nasdaqtrader.com/SymbolDirectory/nasdaqlisted.txt. It is an anonymous FTP page, so when I use my computer's browser, there's no need for a username or password.
I've tried incorporating different codes and tips from the following sources:
Reading Text File From Server on Android
http://examples.javacodegeeks.com/core-java/apache/commons/net-commons/download-file-from-ftp-server/
How to read a text file via FTP?
Reading txt file from an ftp server and returning it from AsyncTask
unable to read file from ftp in android?
Howto do a simple ftp get file on Android
http://www.javaworld.com/article/2073325/java-app-dev/java-ftp-client-libraries-reviewed.html
http://developer.android.com/reference/java/net/URLConnection.html
None of what I've tried above helped. I'm not quite sure what I'm doing wrong.
To be clear, all I want to do is to get the plain text from the posted .txt file. I have no interest in downloading said file onto my device's memory.
If you could provide me with a step-by-step explanation on how to do this, I'd be very thankful.
Ok. I've got it. For those who are in the same boat, the step-by-step answer is below:
A lot of problems other users were encountering could be solved by having permissions for internet turned on in the manifest, but mine was a little more complicated. Turns out, the main trick is to not include ftp:// in the address in Java.* Also, when you are entering an FTP site, make sure you enter via the root page, so my original page of ftp://ftp.nasdaqtrader.com/SymbolDirectory/nasdaqlisted.txt becomes: ftp.nasdaqtrader.com.
Make sure to download and include the right Apache Commons library in your project (here: http://commons.apache.org/proper/commons-net/download_net.cgi).
Connect to the root page:
FTPClient ftpClient = new FTPClient();
ftpClient.connect("ftp.nasdaqtrader.com");
Login anonymously, in this case, both username and password are "anonymous". This might be the case with many FTP pages, but I can't be sure:
ftpClient.login("anonymous", "anonymous");
Then, go to the correct directory (be careful about including/excluding the slashes):
ftpClient.changeWorkingDirectory("/SymbolDirectory");
Finally! You can now get the InputStream from the posted text file:
InputStream is = new BufferedInputStream(ftpClient.retrieveFileStream("nasdaqlisted.txt"));
Then, convert the InputStream into String and manipulate as needed. There are many ways to do this. One of which can be found here: How can I convert InputStream data to String in Android SOAP Webservices
*Source: Android FTP connection Failed
If you get "425 Unable to build data connection: Connection timed out" error, then after connecting to ftp server, I would recommend you to set the local mode to passive mode by the following statement.
ftpClient.enterLocalPassiveMode();
https://saucelabs.com/resources/selenium-file-upload
I am trying to follow the above sample, but I would like to pass the input image file from a HTTP server instead of the local disk. How should I do it? I tried with the HTTP url but it doesn't seem to work as an argument.
You can't directly pass a file that is not on your local drive.
but you can do it in 2 steps:
1 - download the file. ex with http://commons.apache.org/proper/commons-io/:
FileUtils.copyURLToFile(aRemoteUrl, aLocalFile)
2 - upload the local file (as explained in your link)
(you can eventually delete the local file after that)
I'm using apache.commons library for uploading file to a ftp server. It uploads file successful, but then I want to have a link to that file, that anyone can download it. How do I get the URL of uploaded file ?
Thanks.
One of the great features of an FTP server is the ability to use direct FTP links. With a direct link, you can use links to files and directories in emails and on your websites. Think of this: instead of sending a big attachment in an email, send a link to the file instead.
The format is really simple:
ftp:// username [colon] password [at] server.exavault.com [slash] folder-or-filename
For example: ftp://links:pass#test.exavault.com/transfer.pdf
source : http://www.exavault.com/docs/help/faq/transferring/direct-links