Export to GitHub

imageshackapi - issue #20

base64 support for fileupload multipart


Posted on Jan 23, 2011 by Happy Panda

What steps will reproduce the problem? 1. Create a multipart/form-data request 2. Set the mimepart according to the specification 3. Set the Content-Transfer-Encoding: base64 4. Post the data in base64 format

What is the expected output? What do you see instead? The expected output will be something different than a blank page

What version of the product are you using? On what operating system? Using google chrome the http://www.imageshack.us/upload_api.php url

Please provide any additional information below.

below the javascript method to create the xhr request with a base64 data. The dataUrl param comes from canvas.toDataUrl('image/jpeg') or canvas.toDataUrl('image/png')

var xhr = new XMLHttpRequest(); var boundaryString = '------------------------------'; xhr.open('POST','http://www.imageshack.us/upload_api.php'); //xhr.open('POST','http://localhost:8080/Upload/'); xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary="+boundaryString); xhr.onreadystatechange = function() { if (xhr.readyState == 4) { if ((xhr.status >= 200 && xhr.status <= 200) || xhr.status == 304) { if (xhr.responseText != "") { alert(xhr.responseText); // display response. } } }; } dataUrl = dataUrl.substr(dataUrl.indexOf("base64,",0)+7);

    var cr = &quot;\r\n&quot;; 
    var boundary = &quot;--&quot;+ boundaryString;
    var body = boundary + cr;
    body+=&quot;Content-Disposition: form-data; name=\&quot;key\&quot;&quot;+cr+cr;
    body+=&quot;key&quot;+cr;
    body+=boundary+cr;
    body+=&quot;Content-Disposition: form-data; name=\&quot;fileupload\&quot;; filename=\&quot;gprFoto.jpeg\&quot;&quot;+cr;
    body+=&quot;Content-Type: image/jpeg&quot;+cr;
    body+=&quot;Content-Transfer-Encoding: base64&quot;+cr+cr
    body+=dataUrl+ cr;
    body+=boundary+&quot;--&quot;+cr;
    xhr.send(body);

Comment #1

Posted on Dec 7, 2012 by Quick Camel

I am a android developer .I want image upload by the ImageshackApi for android apps.Is it possible.If it possible please send to me the sample code

Status: New

Labels:
Type-Defect Priority-Medium