Skip to main content

Javascipt Load Large Size of File in Blob Type Using AJAX/XMLHttpRequest

Here we show some import code for Load Larger size file uzing http request.

 when you need to load large file in blob type.

 it's Solution For Auto Select File in Select input type.

 Load Your File in Blob Type.

Following is Code.


 
function loadXHR(url) {
 console.log("Load Function Called..");
  return new Promise(function(resolve, reject) {
  try {
             var xhr = new XMLHttpRequest();
             xhr.open("GET", url);
             xhr.responseType = "blob";
             xhr.onerror = function() {reject("Network error.")};
             xhr.onload = function() {
                 if (xhr.status === 200) {
   console.log("Responce done....");
   resolve(xhr.response)
   }else {
   console.log("Error....",xhr.statusText);
   reject("Loading error:" + xhr.statusText)
   }
             };
             xhr.send();
         }
         catch(err) {
   reject(err.message)
  }
     });
 }




 let urlOfEDF = 'PATH_OF_YOUR_FILE';
 loadXHR(urlOfEDF).then(function(FILE_BLOB) {
  var edfReader = new FileReader();
  edfReader.onload = function(event){
   // Here You get Your File in Blob Data
   console.log('Done Loading...',FILE_BLOB);
   
  };
  edfReader.readAsText(FILE_BLOB);
 }); 
 


Easy Wayt To Load any File in Blob. same As Select file.

Thanks.

Comments

  1. Workday HCM Certification Training
    Master Workday HCM modules like Core HR, Payroll, Recruiting, and Security configuration with practical, real-time exercises. Prepare confidently for Workday HCM certification to build a rewarding career in HR technology.

    ReplyDelete

Post a Comment

Popular posts from this blog

NodeJs - Socket.IO Set Ping Timeout & Ping Interval | node-js-tutorial.blogspot.in

How to Socket.io Specifying Heartbeat Here we Learn Method of Set Ping Timeout & ping interval. There Are Several Way to Set Ping interval & Ping Time out. Please Remember Some note : ping interval is alway small then ping Timeout. Always Set Same ping timeout & ping Interval for both side. (Client side  & Server Side) When You Develop any Client Server Application. Following Are some Pattern Which most Case Peopele use. 1) Type One  var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http, { 'pingInterval': 2000, 'pingTimeout': 5000 }); 2) Type Two For package dependency versions: "express": "^4.12.3", "socket.io": "1.0" ex : var app = express(); var server = require('http').createServer(app); var io = require('socket.io')(server); io.set('heartbeat timeout...

How to Use MongoDb Nativ Query With Model in NodeJS | node-js-tutorial.blogspot.com

How to Use MongoDb Nativ Query With Model in NodeJS | node-js-tutorial.blogspot.com In this artical, you have learn how to use mongo native query with node model. let understand some code. Following code use for conver Sting To Object ID. Declare in top of Your code. var ObjectId = require('mongodb').ObjectID; Nativ query Understand Object Id not String. let userId = '123232323232'; // ID of User. Your_Model.native(function (err, modelObj) { modelObj.update({ "_id": new ObjectId(userId) }, { $push: { <feild>: { <feild>: <value> } } }, function (err, res) { if (err) { // Print Error Log console.log(err); } else { // Print Success Log console.log(res.result); } }); }); // End Nativ Here Que...

How To Get Socket(socket.io) Disconnected Reason - Node js | JavaScript

we Define Event handler for Handel "Disconnect" Event. Just Get Reason we use Following Code. socket.on('disconnect', function(reason){    console.log('Player Disconnected Due To Reason :'+reason); }); Start listening for server-sent events from node with the specified eventIdentity. Will trigger the provided callback function when a matching event is received. Here 'disconnect' Event Occure when some socket is disconnected. There Are Following Type of Reason Here we Get. 1) Transport Close 2) Ping Timeout Transport Close : When You Close your Application/Game/Webgl, You May Get this Reason. Ping Timeout : When you ping time is Expire ,  You May Get this Reason. It might be better to set different pingTimeouts on the server and on client. On server, pingTimeout (+pingInterval) means the idle time the server will keep the socket up. This can be quite long, as the client can sleep while the connection is still kept al...