Note that there are some explanatory texts on larger screens.

plurals
  1. POSending a blob to a servlet through ajax
    primarykey
    data
    text
    <p>EDIT: The whole problem turned out to be a network issue, but if you see any ideas on how I could optimize the process I'd still appreciate it.</p> <p>I am fairly new to Servlets and not far into my journey I have encountered a problem, one related to performance. I am trying to send a video file through the XHR object in my Google Chrome browser. The video file is stored in a Blob object. I use this function in my JavaScript script:</p> <pre><code>function upload(blob) { var xhr = new XMLHttpRequest(); xhr.open('POST', '/Test/Odbieracz', true); xhr.onload = function(e) { console.log("loaded"); }; xhr.onreadystatechange = function(){ console.log("state: " + xhr.readyState); }; // Listen to the upload progress. xhr.upload.onprogress = function(e) { console.log("uploading..."); }; xhr.setRequestHeader("Content-Type", "video/webm"); xhr.send(blob); } </code></pre> <p>It works well, because the Blob reaches the Servlet where I use this bit of code to process it:</p> <pre><code>byte[] buffer = new byte[16 * 1024]; InputStream input = request.getInputStream(); OutputStream output = new FileOutputStream("costam0.webm"); int bytesRead; while ((bytesRead = input.read(buffer)) != -1){ System.out.println(bytesRead); output.write(buffer, 0, bytesRead); } output.close(); input.close(); </code></pre> <p>It saves the file as well.</p> <p>The issue I do have is that it is very very slow, according to my calculations it can process about 42kB/s, which for a web service having to do with video files is extremely slow. I have been sitting here for hours trying to find a way to speed it up somehow, or to at least find the bottleneck, but unfortunately I have no idea where it might be.</p> <p>My suspicion is that the browser is causing the lag, I have used a different InputStream in my Servlet leading to a local file (the same one I'm trying to upload through XHR) and it had no issue processing it at all, took less than a second. The server is stationed on my localhost, so I don't think the network is lagging me much at all.</p> <p>If anyone had this issue before, I'd be grateful for any pointers.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload