0

I am trying to make a website in Java and trying to add upload system. I am using the following tag:

<a href="filepath/filename" download > Download It </a>

but the thing is, if the file is text file it doesn't start downloading. Instead it just opens the text. Also when I start the server on eclipse it works fine but when I type the same link in chrome, It says: Failed - Network error.

Any suggestions?

GeorgeDopeG
  • 175
  • 2
  • 14
  • You should read that page, it could be a lead [Chrome Download Attribute not working](https://stackoverflow.com/questions/23872902/chrome-download-attribute-not-working) – AxelH Jun 13 '17 at 07:53

1 Answers1

0

It seems the best way to do that (if the download attribute does not work), is to properly set the header Content-type to application/octet-stream on your resource URI, but this needs a server-side change of course. Potentially, you also have to set Content-Length and Content-Disposition.

That's weird that download does not work in Chrome though: did you try to capture the HTTP exchange?

sjahan
  • 5,720
  • 3
  • 19
  • 42
  • A question in an answer usually means it is not an answer but a comment ;) – AxelH Jun 13 '17 at 07:47
  • The very strange thing is that when I generate the source of page and put the whole text in html, it work just fine even on chrome. But when I do exact same thing from server it gives network error. – GeorgeDopeG Jun 13 '17 at 07:47
  • @GeorgeDopeG have you checked that the link is correct in the generated page (on the client side) that it is not using a cached version or something else – AxelH Jun 13 '17 at 07:48
  • @AxelH I would be glad to comment but my account does not let me do that :( – sjahan Jun 13 '17 at 07:48
  • @AxelH yes. Also it work fine in eclipse browser. And it also works fine when I put the generated html source in just html file. It only give error when I try running it from server on chrome. – GeorgeDopeG Jun 13 '17 at 07:49
  • @sjahan just saying, but using an answer for the wrong reason could lead to downvotes, then it would take you even longer to get the reputation to be able to comment. Just be patient instead of using the wrong tool. – AxelH Jun 13 '17 at 07:50
  • @GeorgeDopeG you means by copying the source from the JSP page received on the client side (so generated by the server), into an HTML page, it works ? Since the browser don't really see a the difference there, maybe in headers, I don't see how it could be possible. – AxelH Jun 13 '17 at 07:52
  • Anyway, I don't know on which technology is based the Eclipse server, but you should try something more production ready. If Chrome tells you there is a network error, it is certainly that the HTTP protocol is not respected! That's why sniffing the HTTP request/response should be interesting. – sjahan Jun 13 '17 at 07:53