Created
June 14, 2020 06:48
-
-
Save AndrewBuntsev/a82462266432390d80d6e369292e4e21 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function UploadVideo(file) { | |
var loaded = 0; | |
var chunkSize = 500000; | |
var total = file.size; | |
var reader = new FileReader(); | |
var slice = file.slice(0, chunkSize); | |
// Reading a chunk to invoke the 'onload' event | |
reader.readAsBinaryString(slice); | |
console.log('Started uploading file "' + file.name + '"'); | |
reader.onload = function (e) { | |
//Send the sliced chunk to the REST API | |
$.ajax({ | |
url: "http://api/url/etc", | |
type: "POST", | |
data: slice, | |
processData: false, | |
contentType: false, | |
error: (function (errorData) { | |
console.log(errorData); | |
alert("Video Upload Failed"); | |
}) | |
}).done(function (e){ | |
loaded += chunkSize; | |
var percentLoaded = Math.min((loaded / total) * 100, 100); | |
console.log('Uploaded ' + Math.floor(percentLoaded) + '% of file "' + file.name + '"'); | |
//Read the next chunk and call 'onload' event again | |
if (loaded <= total) { | |
slice = file.slice(loaded, loaded + chunkSize); | |
reader.readAsBinaryString(slice); | |
} else { | |
loaded = total; | |
console.log('File "' + file.name + '" uploaded successfully!'); | |
} | |
} | |
} | |
} |
Sorry, I am not familiar with php
…On Fri, Apr 30, 2021 at 1:19 AM h-m-p ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks for this script and your explanation on medium! Is it possible to
get some hints on how to handle these chunked uploads server side via a php
script, please? That would be very helpful!
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/a82462266432390d80d6e369292e4e21#gistcomment-3725054>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKWOLS2O74CK5VM7L5CCYPLTLF2JPANCNFSM432DYTDQ>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this script and your explanation on medium! Is it possible to get some hints on how to handle these chunked uploads server side via a php script, please? That would be very helpful!