drupal-client
drupal-client copied to clipboard
Image upload
hello,
the titanium app should allow user to upload an image to his user profile. anyone has this feature working (as there is a comment in the library saying that it has not been tested for a while)?
i get a success rest response ("file" is empty though and filesize is only 25 bytes) but no image has been uploaded
{"fid":"113","uid":"1","filename":"photo.jpg","uri":"s3://photo_2.jpg","filemime":"image/jpeg","filesize":"25","status":"1","timestamp":"1420912934","rdf_mapping":[],"uri_full":"//bucketagain7778.s3.amazonaws.com/photo_2.jpg","target_uri":"photo_2.jpg","file":"","image_styles":[]}
profile.js code
function upload(event){
var photo = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, "photo.jpg");
photo.write(event.media);
setTimeout(function(){
//photo.read();
console.log(JSON.stringify(photo) + "this is stringed photo object");
console.log("Photo.size: " + photo.size);
console.log("photo.nativePath: " + photo.nativePath);
console.log("photo.name: "+ photo.name);
console.log("photo.extension: " + photo.extension); // outputs [object TiFilesystemFile]this is photo extension[object TiFilesystemFile]this is photo extension
var base64data = Ti.Utils.base64encode(photo.toString());
//var base64data = photo.toString('base64');
var filename = photo.name;
var filesize = photo.size;
console.log("filename: " + filename);
console.log("base64data: " + base64data);
console.log("filesize: " + filesize);
drupal.uploadFile(base64data, filename, filesize,
function (response) {
fid = response.fid;
console.log(JSON.stringify(response) + " this is response");
},
function (err) {
console.log(err);
},
function (progress_event) {
console.log(progress_event.loaded + '/' + filesize + ' uploaded');
}
);
},200);
console:
[INFO] : Photo.size: 931061
[INFO] : photo.nativePath: file:///Users/macmini/Library/Developer/CoreSimulator/Devices/5ACEEA5A-F4FF-4A1A-AE59-2D822C19EB58/data/Containers/Data/Application/0B5371B0-90B4-45C0-9859-64A3B1E5ECB5/Documents/photo.jpg
[INFO] : photo.name: photo.jpg
[INFO] : photo.extension: [object TiFilesystemFile]
[INFO] : filename: photo.jpg
[INFO] : base64data: W29iamVjdCBUaUZpbGVzeXN0ZW1GaWxlXQ==
[INFO] : filesize: 931061