Web Analytics Made Easy -
StatCounter how to download and view any file in browser - CodingForum

Announcement

Collapse
No announcement yet.

how to download and view any file in browser

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • how to download and view any file in browser

    I have an application where I am storing file content in database. When I get the bytes back, I don't have the file extension and the byte content can be of any type - such as gif, jpeg, word, pdf. I am not sure what I should set on contentType to view the files.
    If I don't set contentType, it attempts to open the file by the url extension which is not right. Is there a way I can find contentType from the bytes? The browsers I need to support to view the bytes content is IE and mozilla.

  • #2
    You need to store the content type in the database too.
    Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
    I code to specs, and test only in Firefox (unless stated otherwise).

    Comment


    • #3
      better to use standard extension

      Comment


      • #4
        the problem is - when through my application, a user uploads the file, the file may not have an extension (some users just don't have files with extension). In the database, I store the filename and the bytes(blob). Because, the file extension is not provided, when I need to render the file, I am not able to set the proper contenttype. If I set the contentType=application/octet-stream, the browser opens the "File Download" dialog which has option to "Open" or 'Save". I am wondering how I can make it have the "Open With" or the Choose Program dialog?

        Comment


        • #5
          Originally posted by user11
          I am wondering how I can make it have the "Open With" or the Choose Program dialog?
          This is really up to the user agent (browser). Did you save the filename?
          Forget style. Code to semantics. Seperate style from structure, and structure from behaviour.
          I code to specs, and test only in Firefox (unless stated otherwise).

          Comment

          Working...
          X