Skip to content

Instantly share code, notes, and snippets.

@1Marc
Created June 23, 2011 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1Marc/1043311 to your computer and use it in GitHub Desktop.
Save 1Marc/1043311 to your computer and use it in GitHub Desktop.
latest code
var uploadFile = Titanium.Filesystem.getFile(filepath, filename);
var uploadStream = Titanium.Filesystem.getFileStream(uploadFile);
uploadStream.open(Titanium.Filesystem.MODE_READ, true);
content = uploadStream.read();
uploadStream.close();
// content = Titanium.Codec.encodeBase64(content);
// content = Titanium.Codec.encodeHexBinary(content);
var name = "file";
var boundary = '----12345568790';
var header = "--" + boundary + "\r\n";
header += "Content-Disposition: form-data; name=\"" + name + "\";";
header += "filename=\"" + filename + "\"\r\n\"";
header += "Content-Type: application/octet-stream\r\n\r\n";
var fullContent = header + content + "\r\n--" + boundary + "--";
console.log(fullContent);
xhr.addEventListener(Titanium.HTTP_DONE, function(){
console.log("TI DONE!");
console.log(this.responseText);
});
xhr.open('POST', api_url);
xhr.setRequestHeader('Authorization', oa.signRequest("POST", "https://api-content.dropbox.com/0/files/dropbox/JB", {file: escape(file.name)}));
xhr.setRequestHeader("Content-type", "multipart/form-data; boundary=\"" + boundary + "\"");
xhr.setRequestHeader("Connection", "close");
xhr.send(fullContent);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment