I have to split a big file into 2mb parts to be sended into a server but i could not find any way. on angular or javascript. Right now i am using angularFileUpload to get it and send it as a big file. if anyone have a clue please let me know
Asked
Active
Viewed 1.1k times
3
-
Stream the file and read it in chunks maybe http://stackoverflow.com/questions/25810051/filereader-api-on-big-files – prawn Jan 14 '15 at 16:41
3 Answers
4
You have to use the HTML5 file API. More info about it you can find here. I can't provide any code example, mainly because i don't know how your server looks. You have to give the user a transaction token, and he will have to send you the chunk number, chunk data and the token, so you'll be able to re-assemble it on the server.

Mihail Alexe
- 340
- 2
- 9
-
i am reading FileApi i hope all of theses can soported by apiRest because on server side i have a c# app with controllers – Miguel Garcia Boriani Jan 15 '15 at 15:45
-
Great! You can find an example of a server that accepts chunked uploads [here](http://www.codeproject.com/script/Articles/ArticleVersion.aspx?aid=460142&av=669590) – Mihail Alexe Jan 15 '15 at 15:50
-
-
Sorry for the late response. If you plan to target IE6+, you're kinda "doomed". IE6/7/8 doesn't offer an API to do this. You should consider using Adobe Flash, or, because you already know C#, Silverlight :( – Mihail Alexe Jan 19 '15 at 11:46
-
uff our customers are now on IE9+ so i need to find an example of a server that accepts chunked uploads – Miguel Garcia Boriani Jan 20 '15 at 16:05
-
That's great! See above, in my second comment. There's an example made by the guys at "the code project" – Mihail Alexe Jan 20 '15 at 16:07
0
You should be able to use FileAPI. I believe it provides a shim for older browsers that do not support the HTML5 File API.
Here's an example of it being used in the angular-file-upload repo.

Chance
- 11,043
- 8
- 61
- 84
-
i am reading FileApi i hope all of theses can soported by apiRest because on server side i have a c# app with controllers – Miguel Garcia Boriani Jan 15 '15 at 15:50
0
You can try below code , This might help you to read file into chunks. in HTML file . Here Filereader is reading as text, but we can choose other way like reading as buffer etc.
and in ts file
uploadDoc(event) {
let lastChunksize = 0;
var file = event.target.files[0];
this.readFile(file, lastChunksize, this.myCallback.bind(this));
}
myCallback(file, lastChunksize, result) {
lastChunksize = lastChunksize + 20000;
if(result) {
//Add you logic what do you want after reading the file
this.readFile(file, lastChunksize, this.myCallback.bind(this));
} else {
///end recursion
}
}
readFile(file,lastChunksize: number, callback) {
var fileBlob = file.slice(lastChunksize,lastChunksize+20000);
if(fileBlob.size !=0) {
let fileReader = new FileReader();
fileReader.onloadend= (result)=>{
return callback(file,lastChunksize,fileReader.result)
}
fileReader.readAsText(fileBlob);
}else {
return callback(file,lastChunksize,false);
}
}

Akhand P Singh
- 1
- 2