Created
February 2, 2012 00:03
-
-
Save yec/1720276 to your computer and use it in GitHub Desktop.
sample function for file upload
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Drupal.file = { | |
create : function(file_raw) { | |
var url = 'http://74.82.57.136/gsk/?q=api/file/create_raw'; | |
var xhr = Titanium.Network.createHTTPClient(); | |
xhr.onload = function() { | |
var file_object = JSON.parse(this.responseText); | |
Ti.API.log(file_object); | |
// Return a file info object. file_object[0].fid is the file id to reference | |
Ti.fireEvent('drupal:file:created', file_object[0]); | |
} | |
xhr.onerror = function() { | |
Ti.API.log(this.responseText); | |
Ti.API.log(this.status); | |
//Drupal.user.logout(); | |
} | |
// file_raw is event.media | |
data = {'files[file_contents]' : file_raw}; | |
xhr.open("POST", url); | |
xhr.setRequestHeader('Accept', 'application/json'); | |
xhr.setRequestHeader('Content-Type', 'multipart/form-data'); | |
xhr.setRequestHeader('Connection', 'close'); | |
xhr.send(data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment