-6

This URL file download Does not contain suffix :

https://dw.uptodown.com/dwn/RjLGfwlqXE8U-QGjvr3tuGHmKLtjYKqg_TJ89FpUVMvOQOrwaQZfbKU7yi0_7VIGqwrDC7xBxgpoWaUecbV7Sc6JGKZhlZC6m3gQ1tlfN7ipEsJHIDtL6AyFeutWSJIJ/Q-C7ucM5Og9Yt2ON85LQ5-_qZBkr51nQ10ZW75CJKbAh4dyuwZmX8c8vIZiZ3f3wm_ktiTbOYp4YZeG2M2qaFeyeHhNVLpSJjw2PCkydbLZlsLqf7wckDKMhNGcXeXn3/QOce-Iafv9bKdHIuNe8qMAAJE9s-jdyfgH_AHYsUmBtwUD-6n3zpGgz0ePURsyhj/

how can I know its type in java Note: Google Chrome can know the link type does this help solve the problem by chrome.downloads.download or javascript

//===================================================

url = new URL(file.stringUrl);

urlConnection = (URLConnection) url.openConnection();

System.out.println(urlConnection.getContentLength());

String mimeType = urlConnection.getContentType(); //here error

System.out.println(mimeType);

urlConnection.connect();

//===================================================

  • That is based on the service presenting the data. They send it via the header of the file, which is how the browsers know. If the server doesn't tell you the type, you will not know unless the file creator adds it to the header internally. – Chizl May 04 '19 at 21:24
  • but internet download manger can know the file type and Chrome browser also can do this when downloading – Mohamad AboAzan May 09 '19 at 05:16
  • BTW, no one will ever click on any external links here. People try to setup ads, then have people click them here so they can get paid.. It's a no no for any unknown domains. – Chizl May 10 '19 at 12:35

1 Answers1

0

There are two headers involved here. File header and Response header from IIS or any other web server is being used. File header some times have the type of file in it. PNG or GIF files for example.

enter image description here

If you open them in a hex editor you will see they state they are PNG or GIF files, so no matter what the file extension is, you know it's a PNG or GIF. Most files do not do that. This is when you must rely on the web developer that is presenting you the file to be downloaded. In Java/ASP.NET or what ever language the server developer wrote their site in, they can present a content type and the filename to be sent to the requester, as seen in this post: as seen in this post

Hope that helps..

Chizl
  • 2,004
  • 17
  • 32