Send file to OneDrive API using Javascript
<p>I have some problems uploading files to the "OneDrive Api".</p>

<p>I get the URL to upload de file:</p>

<pre><code> $.ajax({
                    type: "POST",
                    url: folderUrl,
                    headers: {
                        'Authorization': 'Bearer ' + access_token,
                        'Content-Type': 'application/json',
                    },
                    success: {.....}
});
</code></pre>

<p>And with it i get the "upload url". THen i read and upload the file that the user select (I need fragment the file):</p>

<pre><code>var fileInput = $("#file");
var fileList = fileInput[0].files;
var file = fileList[0];
content_length = file.size;
inicio = 0;
var blob = file.slice(inicio, content_length);

fileReader.onloadend = function (evt) {
    if (evt.target.readyState == FileReader.DONE) { // DONE == 2
        var result = evt.target.result;

        $.ajax({
            method: "PUT",
            url: uploadUrl,
            headers: {
                'Authorization': 'Bearer ' + access_token,
                'Content-Range': "bytes " + inicio + "-" + ((inicio + evt.target.result.length)-1) + "/" + content_length,
            },
            data: result,
            success: function (result) {
                console.log("subió");
            },
            error: function (error) {
                console.log("falló");
                console.log(JSON.stringify(error, null));
            }
        })
        .done(function (msg) {
            alert("Data Saved: " + msg);
        });
    }
};

fileReader.readAsBinaryString(blob);
</code></pre>

<p>When i upload text files with content like</p>

<blockquote>
  <p>"Lorem ipsum dolor sit amet" (without special characters 'ñ', 'á',
  etc...)</p>
</blockquote>

<p>It work.</p>

<p>But, when upload files with especial characters ("ñ", "á", "¿"....) show the error:</p>

<pre><code>"code":"invalidRequest","message":"**Declared fragment length does not match the provided number of bytes**"
</code></pre>

<p>With files like ".doc", ".zip" and more too.</p>

<p>[EDIT]: I noticed the "á" change for "Ã¡" (For example).</p>

<p>I need help :/</p>

<p>Thanks</p>