You must Sign In to post a response.
  • Category: ASP.NET

    How upload mime type in javascript

    I am developing an app where a user uploads PDF files to the server, via a FileUpload control.

    As part of the usual security/reliability checks I wanted to verify that the uploaded document was actually
    a PDF, not just say, a Text file renamed to have a .PDF extension. Now i want in javascript. means client site.

    protected void Button1_Click(object sender, EventArgs e)
    {
    System.IO.BinaryReader r = new System.IO.BinaryReader(FileUpload2.PostedFile.InputStream);
    string fileclass = "";
    byte buffer;
    try
    {
    buffer = r.ReadByte();
    fileclass = buffer.ToString();
    buffer = r.ReadByte();
    fileclass += buffer.ToString();
    }
    catch
    {
    }
    r.Close();
    if(fileclass!="3780")
    {
    ltl_status.Text = "<p>Error - The upload file must be in PDF format.</p>"
    return;
    }
    }
  • #768495
    Hi,
    For PDF, standard MIME type is 'application/pdf'.
    Please refer this also:
    https://www.maxcdn.com/one/tutorial/mime-types/

  • #768514
    You can try this to upload mime type in javascript
    <input type="file" id="your-files" multiple>
    <script>
    var control = document.getElementById("your-files");
    control.addEventListener("change", function(event) {
    var files = control.files,
    for (var i = 0; i < files.length; i++) {
    console.log("Filename: " + files[i].name);
    console.log("Type: " + files[i].type);
    console.log("Size: " + files[i].size + " bytes");
    }
    }, false);
    </script>


  • Sign In to post your comments