I've got file uploading working, except in one particular case. Here's my code.
Titanium.Media.openPhotoGallery({ success:function(event) { uploader.upload({ files: event.media }, { success: function(response) { cb(response.id, filename); } }); },
var upload = function(data, options) { parentView.add(view); $.progress.show(); options = options || {} var xhr = Titanium.Network.createHTTPClient(); xhr.onload = function(e) { var response = JSON.parse(this.responseText)[0]; if (options.success) options.success(response) close(); }; xhr.onerror = function(e) { Ti.API.error(e); alert('Upload failed. Try again.'); if (options.error) options.error() close(); }; //xhr.setRequestHeader("enctype", "multipart/form-data"); xhr.open('POST', Alloy.CFG.vaultUrl + 'secure/' + Ti.App.Properties.getString('vaultToken')); xhr.onsendstream = function(e) { if (options.progress) options.progress() $.progress.max = 1; $.progress.value = e.progress; }; xhr.send(data); }Now this works most of the time, except if I choose to upload from the "Gallery" and choose an image from a Picasa album.
I've isolated this further to the blob object itself. If I call event.media.length I get this stack trace.
[ERROR] : TiMedia: (main) [1828,30634] OnResult called: -1 [WARN] : W/System.err: java.lang.NullPointerException [WARN] : W/System.err: at java.io.File.fixSlashes(File.java:185) [WARN] : W/System.err: at java.io.File.<init>(File.java:134) [WARN] : W/System.err: at org.appcelerator.titanium.io.TitaniumBlob.getFile(TitaniumBlob.java:77) [WARN] : W/System.err: at org.appcelerator.titanium.TiBlob.getLength(TiBlob.java:315) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.nativeInvoke(Native Method) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.callSync(V8Function.java:57) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function.call(V8Function.java:43) [WARN] : W/System.err: at org.appcelerator.kroll.runtime.v8.V8Function$1.run(V8Function.java:70) [WARN] : W/System.err: at android.os.Handler.handleCallback(Handler.java:733) [WARN] : W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95) [WARN] : W/System.err: at android.os.Looper.loop(Looper.java:136) [WARN] : W/System.err: at org.appcelerator.kroll.KrollRuntime$KrollRuntimeThread.run(KrollRuntime.java:112) [ERROR] : TiExceptionHandler: (main) [98,30732] ----- Titanium Javascript Runtime Error ----- [ERROR] : TiExceptionHandler: (main) [0,30732] - In alloy/controllers/gallery.js:1,69 [ERROR] : TiExceptionHandler: (main) [1,30733] - Message: Uncaught Error: Java Exception occurred [ERROR] : TiExceptionHandler: (main) [0,30733] - Source: nium.Media.openPhotoGallery({success:function(t){Ti.API.info(t.media.length);v [ERROR] : V8Exception: Exception occurred at alloy/controllers/gallery.js:1: Uncaught Error: Java Exception occurredAny suggestions?