Skip to content

Instantly share code, notes, and snippets.

@dsifry
Created August 1, 2010 18:30
Show Gist options
  • Save dsifry/503612 to your computer and use it in GitHub Desktop.
Save dsifry/503612 to your computer and use it in GitHub Desktop.
function post_pic_data(user,pass,storagevariable) {
data = localStorage.getItem(storagevariable);
if (data == null) {
alert("No picture selected");
}
alert("About to send data");
var dis = this;
var url = "http://example.com/newmobile.php";
var boundary = "----WebKitFormBoundary";
var datastr = boundary + "\n" + 'Content-Disposition: form-data; name="activity[photo_attributes][pic]"; filename="image.jpg"' +
"\nContent-Type: image/jpeg\n\n" + data + boundary;
console.log(datastr);
x$('#results').xhr(url,
{
headers: [
{
name: "Authorization",
value: "Basic " + btoa(user + ":" + pass)
},
{
name: "Content-Type",
value: "multipart/form-data; boundary=" + boundary
},
{
name: "Cache-Control",
value: "no-cache"
},
],
data: datastr,
method: "post",
async: true,
callback:function(incoming) {
alert(incoming);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment