Note that there are some explanatory texts on larger screens.

plurals
  1. POUpload file from Javascript
    text
    copied!<p>I'm developing a <strong>Javascript</strong> app and I need to use the <strong>Mediafire REST API</strong> to upload a file. (See upload ducmentation <a href="http://developers.mediafire.com/index.php/REST_API#upload" rel="nofollow noreferrer"><strong>here</strong></a>).</p> <p>Following this <a href="https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications" rel="nofollow noreferrer"><strong>MDN tutorial</strong></a>, and some research, I've written the code below, but it seems it's not working... Note that I don't need for the moment to control the progress and so on, I only want to do the most basic upload operation possible...</p> <p>Also note that I could a different code, and even jQuery or other (free) libraries, so if you have a better code to upload a file I'd be really grateful...</p> <pre><code>var controller = this; var file = $("#file").get(0).files[0]; //The file is correctly retrieved here... var xhr = new XMLHttpRequest(); xhr.open('POST', 'http://www.mediafire.com/api/upload/upload.php?session_token=' + controller.sessionToken.token); //(The session_token is valid) xhr.overrideMimeType('text/plain; charset=x-user-defined'); xhr.setRequestHeader('x-filesize', file.size); var reader = new FileReader(); reader.onload = function (evt) { var uInt8Array = new Uint8Array(evt.target.result); //It seems that here the ArrayBuffer is read correctly, //and I converted it to a ArrayBufferView because Chrome suggested it... xhr.send(uInt8Array); }; reader.readAsArrayBuffer(file); </code></pre> <p>I can't tell the concrete error, I only know that nothing is happens... but maybe looking at the code you can see some obvious error... The only thing I see is this in Chrome's console:</p> <p><img src="https://i.stack.imgur.com/ikrnm.png" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/ILa1O.png" alt="enter image description here"></p> <p><em>Note: I know the quality of this question is not the desired and it's TOO vague, but I tried to do my best taking into account that I'm completely new to ALL these technologies...</em> </p>
 

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