Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9139855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:26:29+00:00 2026-06-17T09:26:29+00:00

I created a test for local file handling, but can’t get the ‘file’ type

  • 0

I created a test for local file handling, but can’t get the ‘file’ type to return any contents in Chrome or Firefox. Chrome gives no error and acts like there was never a call to the FileReader(), and Firefox gives a strange error. FileReader() works fine on the Blob type. Any ideas? See test code below:

<head>

<script language="JavaScript" type="text/javascript">

var ContentString='(empty)';

var reader = new FileReader();
var testBLOB = new Blob(['Test Blob'], { "type" : "text/plain" });
reader.onload = function(event) {ContentString = event.target.result;};
reader.onerror = function(event) {alert('Load error!');};

function WriteContents(Iteration,FileOrBlob) 
{
    if (Iteration==0) 
    {
        if (FileOrBlob==0) 
        {
            try 
            {
            var fileUpload=document.getElementById("inputFile");
            //alert(fileUpload.type);
            reader.readAsText(fileUpload/*, "UTF-8"*/);
            }
            catch(err) {alert(err.message);}
        }
            else
        {
        reader.readAsText(testBLOB/*, "UTF-8"*/);
        }
    }

    document.getElementById("Iteration").innerHTML=Iteration;
    document.getElementById("ContentString").innerHTML=ContentString;
    document.getElementById("error").innerHTML=reader.error;
    document.getElementById("readyState").innerHTML=reader.readyState;
    document.getElementById("result").innerHTML=reader.result;

    setTimeout('WriteContents('+(Iteration+1)+','+FileOrBlob+');',5000);
}

if (window.File && window.FileReader && window.FileList && window.Blob)  {document.write('OK<br>');} else {document.write('Browser Error<br>');}

</script>

</head>

<br>
<input type="file" id="inputFile" name="inputFile" onchange="WriteContents(0,0);">&nbsp;
<input type="button" onclick="WriteContents(0,1);" value="Use Test Blob">
<br><br>
<table border=1>
<tr><td>Iteration</td><td id="Iteration">Choose File or Blob Above (one time only please!)</td></tr>
<tr><td>ContentString</td><td id="ContentString"></td></tr>
<tr><td>error</td><td id="error"></td></tr>
<tr><td>readyState</td><td id="readyState"></td></tr>
<tr><td>result</td><td id="result"></td></tr>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:26:30+00:00Added an answer on June 17, 2026 at 9:26 am

    Found the answer in this post:

    File API: Returns file reference (object) or whole file content (string)?

    You need to access the blob part of the ‘file’ – these lines

    var fileUpload=document.getElementById("inputFile");
    reader.readAsText(fileUpload/*, "UTF-8"*/);
    

    should be

    var fileUpload=document.getElementById("inputFile").files[0];
    reader.readAsText(fileUpload/*, "UTF-8"*/);
    

    Only 9 characters out!!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a empty test project (static library type) with enabling the unit test.
On my 000webhost website I had created this SQL file, named test.sql Here is
Situation:- I have created a installation setup(local) that returns a URL eg:- ved.test.com which
I created a phpunit test file , when I try to run it via
I've created a Grails plugin which adds a custom test type class (extending GrailsTestTypeSupport
HI. i am trying to open a local file from xml created by xlink
I have created a simple test (just to download a file from famous site
I allow my users to import local and remote files, but how can I
I created a test application that generates 10k random numbers in a range from
I have created a test table in MySQL and would like to insert 10

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.