Problem
When using Ti.Network.createHTTPclient to submit files Windows sends non-nonsensical repeating combination of "%00%00%00%00%00%00%00%00%00%" for the file instead of blob/base64 file. Other values appear to be corrupted as well. iOS & Android perform as expected and submit a parse-able muli-part form data. This issue is stopping us from going live on windows...
Test Case
var url = 'https://wul06jzgd0yn.runscope.net'; //use favorite inspector here...
function go() {
Titanium.Media.showCamera({
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
success: function(event) {
if (event.mediaType == Ti.Media.MEDIA_TYPE_PHOTO) {
var newId = new Date().getTime();
var newName = 'HEY_YOU_GUYS_WAIT_FOR_ME-' + newId;
var fileName = newName + '.jpg';
var imageFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, fileName);
imageFile.write(event.media);
console.log(imageFile.nativePath);
var client = Ti.Network.createHTTPClient({
onload: function(e) {
alert('success');
},
onerror: function(err) {
alert('error');
}
});
client.open("POST", url);
var f = {
name: newName,
attachment: imageFile.read(imageFile)
};
client.send(f);
}
},
cancel: function() {
console.log('camera cancel');
},
error: function(error) {
console.log('camera error');
}
});
}
go();
Discussions
Expect windows to perform as iOS & Android do.
Hello, Thanks for reporting. We really appreciate your contribution. However I am not actually able to reproduce this issue yet. It will be appreciated if you provide full test code and steps also explain the issue a bit more. Thanks in advance
The issue is well defined, when submitting a file it is not submitting a base64 encoded file it is submitting something and unknown encoding. Is it hex? Why? It's not base64. I have no idea what it is submitting. The full code to replicate the issue is attached. Please review the code under Test Case titled app.js. The code runs on Windows, iOS & Android without error and should be beyond simple to replicate the problem. 1. It launches the camera. 2. It takes a picture and submit's it to a web service of your choosing. You will need to define a web service inspector of you choosing at the beginning of the code. Our enterprise uses runscope but there are free ones like requestb.in
The code will alert success that it has successfully called the service, please don't confuse that with it actually submitting that is coherent. You will need to inspect the call to see that is broken. I suppose you could use something like Charles or Fiddler to proxy the call and inspect it as well.
Hello, I am able to reproduce this issue. *Steps:* 1. Create a default classic project for windows and android. 2. Replace code in app.js with following.
3. Add following portion in tiapp.xml.
4. Build and run. 5. Click "Take Photo" >> Select a photo from gallery. 6. Wait for the photo to be uploaded. 7. After success alert see data in server. For android in
http://requestb.in
uploaded data is well recognized for name and raw body. *name:**raw body:*
For Windows name is corrupted and raw body is not well recognised. *name:*
*raw body:*
Thanks *Environment*: *Device info:* Nexus7 (android 6.0.1), Microsoft Lumia 640(Windows Phone 8.1) *Node.js Version:* 0.12.7 *npm Version:* 2.11.3 *Titanium SDKs:* 5.3.0.v20160404105211 *Java Development Kit Version:* 1.8.0_73 *Titanium CLI Version:* 5.0.5 *Appcelerator CLI Version:* 5.2.2 *Appcelerator Studio:* 4.5.0
Link to Appcelerator documentation on file uploads and downloads with similar example code. http://docs.appcelerator.com/platform/latest/#!/guide/File_Uploads_and_Downloads
https://github.com/appcelerator/titanium_mobile_windows/pull/713
Verified using: Windows 10 Pro Ti SDK: 5.4.0.v20160629063537 Appc NPM: 4.2.7-2 Appc CLI: 5.4.0-23 Appc Studio: 4.7.0.201606220541 Lumia 930: 10.0 Lumia 520: 8.1 Images can now be submitted on Windows and the data sent matches that of an application built to Android. Closing ticket