snipt

Ctrl+h for KB shortcuts

JavaScript+Genshi Text

media (blob) and content-length problem from android

xhr.open('PUT', this.STORAGE_URL + '/' + container + '/' + filename); 	
xhr.setRequestHeader('X-Auth-Token', this.TOKEN); 
xhr.setRequestHeader('Content-Type', media.getMimeType()); 
xhr.setRequestHeader('Content-Length', media.getLength()); 
	
//we'll set some meta data if the user has passed it
if(meta != null){
   for(var key in meta){
	xhr.setRequestHeader('X-Object-Meta-' + key.toString(), meta[key].toString());  
   }
}
	
xhr.send(media);

/*
--------
error output below, important bit being Content-Length header already present
if i don't set the content-length header the upload will appear to work but will send the wrong content length (always 15 bytes)
--------
*/

W/IdleConnectionHandler(  479): Removing a connection that never existed!
E/TiHttpClient(  479): (TiHttpClient-3) [8,771] HTTP Error (org.apache.http.client.ClientProtocolException): Content-Length header already present
E/TiHttpClient(  479): org.apache.http.client.ClientProtocolException
E/TiHttpClient(  479): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
E/TiHttpClient(  479): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:653)
E/TiHttpClient(  479): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:637)
E/TiHttpClient(  479): 	at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1140)
E/TiHttpClient(  479): 	at java.lang.Thread.run(Thread.java:1019)
E/TiHttpClient(  479): Caused by: org.apache.http.ProtocolException: Content-Length header already present
E/TiHttpClient(  479): 	at org.apache.http.protocol.RequestContent.process(RequestContent.java:70)
E/TiHttpClient(  479): 	at org.apache.http.protocol.BasicHttpProcessor.process(BasicHttpProcessor.java:290)
E/TiHttpClient(  479): 	at org.apache.http.protocol.HttpRequestExecutor.preProcess(HttpRequestExecutor.java:160)
E/TiHttpClient(  479): 	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:401)
E/TiHttpClient(  479): 	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
E/TiHttpClient(  479): 	... 4 more
I/TiHttpClient(  479): (TiHttpClient-3) [9,780] Sending error Content-Length header already present
E/TiAPI   (  479): ERROR: [object Object]
D/dalvikvm(  452): GC_EXPLICIT freed 73K, 51% free 2865K/5767K, external 1461K/1740K, paused 66ms
https://snipt.net/embed/e5f16226e1788e7e6edfac43678977f9/
/raw/e5f16226e1788e7e6edfac43678977f9/
e5f16226e1788e7e6edfac43678977f9
js+genshitext
JavaScript+Genshi Text
40
2019-05-27T06:15:44
True
False
False
/api/public/snipt/34752/
media-blob-and-content-length-problem-from-android
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a> <a href="#L-18">18</a> <a href="#L-19">19</a> <a href="#L-20">20</a> <a href="#L-21">21</a> <a href="#L-22">22</a> <a href="#L-23">23</a> <a href="#L-24">24</a> <a href="#L-25">25</a> <a href="#L-26">26</a> <a href="#L-27">27</a> <a href="#L-28">28</a> <a href="#L-29">29</a> <a href="#L-30">30</a> <a href="#L-31">31</a> <a href="#L-32">32</a> <a href="#L-33">33</a> <a href="#L-34">34</a> <a href="#L-35">35</a> <a href="#L-36">36</a> <a href="#L-37">37</a> <a href="#L-38">38</a> <a href="#L-39">39</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">xhr</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="s1">&#39;PUT&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">STORAGE_URL</span> <span class="o">+</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="nx">container</span> <span class="o">+</span> <span class="s1">&#39;/&#39;</span> <span class="o">+</span> <span class="nx">filename</span><span class="p">);</span> </span><span id="L-2"><a name="L-2"></a><span class="nx">xhr</span><span class="p">.</span><span class="nx">setRequestHeader</span><span class="p">(</span><span class="s1">&#39;X-Auth-Token&#39;</span><span class="p">,</span> <span class="k">this</span><span class="p">.</span><span class="nx">TOKEN</span><span class="p">);</span> </span><span id="L-3"><a name="L-3"></a><span class="nx">xhr</span><span class="p">.</span><span class="nx">setRequestHeader</span><span class="p">(</span><span class="s1">&#39;Content-Type&#39;</span><span class="p">,</span> <span class="nx">media</span><span class="p">.</span><span class="nx">getMimeType</span><span class="p">());</span> </span><span id="L-4"><a name="L-4"></a><span class="nx">xhr</span><span class="p">.</span><span class="nx">setRequestHeader</span><span class="p">(</span><span class="s1">&#39;Content-Length&#39;</span><span class="p">,</span> <span class="nx">media</span><span class="p">.</span><span class="nx">getLength</span><span class="p">());</span> </span><span id="L-5"><a name="L-5"></a> </span><span id="L-6"><a name="L-6"></a><span class="c1">//we&#39;ll set some meta data if the user has passed it</span> </span><span id="L-7"><a name="L-7"></a><span class="k">if</span><span class="p">(</span><span class="nx">meta</span> <span class="o">!=</span> <span class="kc">null</span><span class="p">){</span> </span><span id="L-8"><a name="L-8"></a> <span class="k">for</span><span class="p">(</span><span class="kd">var</span> <span class="nx">key</span> <span class="k">in</span> <span class="nx">meta</span><span class="p">){</span> </span><span id="L-9"><a name="L-9"></a> <span class="nx">xhr</span><span class="p">.</span><span class="nx">setRequestHeader</span><span class="p">(</span><span class="s1">&#39;X-Object-Meta-&#39;</span> <span class="o">+</span> <span class="nx">key</span><span class="p">.</span><span class="nx">toString</span><span class="p">(),</span> <span class="nx">meta</span><span class="p">[</span><span class="nx">key</span><span class="p">].</span><span class="nx">toString</span><span class="p">());</span> </span><span id="L-10"><a name="L-10"></a> <span class="p">}</span> </span><span id="L-11"><a name="L-11"></a><span class="p">}</span> </span><span id="L-12"><a name="L-12"></a> </span><span id="L-13"><a name="L-13"></a><span class="nx">xhr</span><span class="p">.</span><span class="nx">send</span><span class="p">(</span><span class="nx">media</span><span class="p">);</span> </span><span id="L-14"><a name="L-14"></a> </span><span id="L-15"><a name="L-15"></a><span class="cm">/*</span> </span><span id="L-16"><a name="L-16"></a><span class="cm">--------</span> </span><span id="L-17"><a name="L-17"></a><span class="cm">error output below, important bit being Content-Length header already present</span> </span><span id="L-18"><a name="L-18"></a><span class="cm">if i don&#39;t set the content-length header the upload will appear to work but will send the wrong content length (always 15 bytes)</span> </span><span id="L-19"><a name="L-19"></a><span class="cm">--------</span> </span><span id="L-20"><a name="L-20"></a><span class="cm">*/</span> </span><span id="L-21"><a name="L-21"></a> </span><span id="L-22"><a name="L-22"></a><span class="nx">W</span><span class="o">/</span><span class="nx">IdleConnectionHandler</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">Removing</span> <span class="nx">a</span> <span class="nx">connection</span> <span class="nx">that</span> <span class="nx">never</span> <span class="nx">existed</span><span class="o">!</span> </span><span id="L-23"><a name="L-23"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="p">(</span><span class="nx">TiHttpClient</span><span class="o">-</span><span class="mi">3</span><span class="p">)</span> <span class="p">[</span><span class="mi">8</span><span class="p">,</span><span class="mi">771</span><span class="p">]</span> <span class="nx">HTTP</span> <span class="nb">Error</span> <span class="p">(</span><span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">client</span><span class="p">.</span><span class="nx">ClientProtocolException</span><span class="p">)</span><span class="o">:</span> <span class="nx">Content</span><span class="o">-</span><span class="nx">Length</span> <span class="nx">header</span> <span class="nx">already</span> <span class="nx">present</span> </span><span id="L-24"><a name="L-24"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">client</span><span class="p">.</span><span class="nx">ClientProtocolException</span> </span><span id="L-25"><a name="L-25"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">impl</span><span class="p">.</span><span class="nx">client</span><span class="p">.</span><span class="nx">AbstractHttpClient</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">AbstractHttpClient</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">557</span><span class="p">)</span> </span><span id="L-26"><a name="L-26"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">impl</span><span class="p">.</span><span class="nx">client</span><span class="p">.</span><span class="nx">AbstractHttpClient</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">AbstractHttpClient</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">653</span><span class="p">)</span> </span><span id="L-27"><a name="L-27"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">impl</span><span class="p">.</span><span class="nx">client</span><span class="p">.</span><span class="nx">AbstractHttpClient</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">AbstractHttpClient</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">637</span><span class="p">)</span> </span><span id="L-28"><a name="L-28"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">ti</span><span class="p">.</span><span class="nx">modules</span><span class="p">.</span><span class="nx">titanium</span><span class="p">.</span><span class="nx">network</span><span class="p">.</span><span class="nx">TiHTTPClient</span><span class="nv">$ClientRunnable.run</span><span class="p">(</span><span class="nx">TiHTTPClient</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">1140</span><span class="p">)</span> </span><span id="L-29"><a name="L-29"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">java</span><span class="p">.</span><span class="nx">lang</span><span class="p">.</span><span class="nx">Thread</span><span class="p">.</span><span class="nx">run</span><span class="p">(</span><span class="nx">Thread</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">1019</span><span class="p">)</span> </span><span id="L-30"><a name="L-30"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">Caused</span> <span class="nx">by</span><span class="o">:</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">ProtocolException</span><span class="o">:</span> <span class="nx">Content</span><span class="o">-</span><span class="nx">Length</span> <span class="nx">header</span> <span class="nx">already</span> <span class="nx">present</span> </span><span id="L-31"><a name="L-31"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">protocol</span><span class="p">.</span><span class="nx">RequestContent</span><span class="p">.</span><span class="nx">process</span><span class="p">(</span><span class="nx">RequestContent</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">70</span><span class="p">)</span> </span><span id="L-32"><a name="L-32"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">protocol</span><span class="p">.</span><span class="nx">BasicHttpProcessor</span><span class="p">.</span><span class="nx">process</span><span class="p">(</span><span class="nx">BasicHttpProcessor</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">290</span><span class="p">)</span> </span><span id="L-33"><a name="L-33"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">protocol</span><span class="p">.</span><span class="nx">HttpRequestExecutor</span><span class="p">.</span><span class="nx">preProcess</span><span class="p">(</span><span class="nx">HttpRequestExecutor</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">160</span><span class="p">)</span> </span><span id="L-34"><a name="L-34"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">impl</span><span class="p">.</span><span class="nx">client</span><span class="p">.</span><span class="nx">DefaultRequestDirector</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">DefaultRequestDirector</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">401</span><span class="p">)</span> </span><span id="L-35"><a name="L-35"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">at</span> <span class="nx">org</span><span class="p">.</span><span class="nx">apache</span><span class="p">.</span><span class="nx">http</span><span class="p">.</span><span class="nx">impl</span><span class="p">.</span><span class="nx">client</span><span class="p">.</span><span class="nx">AbstractHttpClient</span><span class="p">.</span><span class="nx">execute</span><span class="p">(</span><span class="nx">AbstractHttpClient</span><span class="p">.</span><span class="nx">java</span><span class="o">:</span><span class="mi">555</span><span class="p">)</span> </span><span id="L-36"><a name="L-36"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="p">...</span> <span class="mi">4</span> <span class="nx">more</span> </span><span id="L-37"><a name="L-37"></a><span class="nx">I</span><span class="o">/</span><span class="nx">TiHttpClient</span><span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="p">(</span><span class="nx">TiHttpClient</span><span class="o">-</span><span class="mi">3</span><span class="p">)</span> <span class="p">[</span><span class="mi">9</span><span class="p">,</span><span class="mi">780</span><span class="p">]</span> <span class="nx">Sending</span> <span class="nx">error</span> <span class="nx">Content</span><span class="o">-</span><span class="nx">Length</span> <span class="nx">header</span> <span class="nx">already</span> <span class="nx">present</span> </span><span id="L-38"><a name="L-38"></a><span class="nx">E</span><span class="o">/</span><span class="nx">TiAPI</span> <span class="p">(</span> <span class="mi">479</span><span class="p">)</span><span class="o">:</span> <span class="nx">ERROR</span><span class="o">:</span> <span class="p">[</span><span class="nx">object</span> <span class="nb">Object</span><span class="p">]</span> </span><span id="L-39"><a name="L-39"></a><span class="nx">D</span><span class="o">/</span><span class="nx">dalvikvm</span><span class="p">(</span> <span class="mi">452</span><span class="p">)</span><span class="o">:</span> <span class="nx">GC_EXPLICIT</span> <span class="nx">freed</span> <span class="mi">73</span><span class="nx">K</span><span class="p">,</span> <span class="mi">51</span><span class="o">%</span> <span class="nx">free</span> <span class="mi">2865</span><span class="nx">K</span><span class="o">/</span><span class="mi">5767</span><span class="nx">K</span><span class="p">,</span> <span class="nx">external</span> <span class="mi">1461</span><span class="nx">K</span><span class="o">/</span><span class="mi">1740</span><span class="nx">K</span><span class="p">,</span> <span class="nx">paused</span> <span class="mi">66</span><span class="nx">ms</span> </span></pre></div> </td></tr></table>
android, blob, content-length, titanium