[TIMOB-15509] Android: HTTPClient cannot send POST data as Ti.Filesystem.File
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2017-07-25T22:33:23.000+0000 |
Affected Version/s | Release 3.2.0 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Benjamin Hatfield |
Assignee | Eric Merriman |
Created | 2013-10-17T00:12:51.000+0000 |
Updated | 2017-07-25T22:33:23.000+0000 |
Description
ENVIRONMENT:
Mac OS X 10.8.4
Appcelerator Studio, build: 3.2.0.201310141852
TiSDK 3.2.0.v20131015134843
Android 4.2.2 / API Level 17
iOS 7.0 / Xcode 5
REPRODUCTION:
1. Add/run the server code on your machine with Apache and PHP enabled. I placed mine in my ~/Sites/ directory.
2. Replace with your local IP (and "/~username" if needed).
3. Run the code below in the Android emulator and press the Submit button.
RESULTS:
Emulator reports the following error:
{noformat}
E/TiExceptionHandler( 3692): (main) [239,3117] ----- Titanium Javascript Runtime Error -----
E/TiExceptionHandler( 3692): (main) [2,3119] - In ti:/httpclient.js:28,9
E/TiExceptionHandler( 3692): (main) [26,3145] - Message: Uncaught Error: size < 0
E/TiExceptionHandler( 3692): (main) [2,3147] - Source: _send.call(this, options);
{noformat}
EXPECTED RESULTS:
Client request should not fail. Server script should return the HTTP headers sent to it.
OTHER INFO:
Works fine on iOS. Able to successfully send JSON object, Blob and String on Android.
SERVER CODE (server.php):
<?php
if(strtoupper($_SERVER['REQUEST_METHOD']) === 'POST') {
echo json_encode((object) array('header' => apache_request_headers()));
}
?>
CLIENT CODE (app.js):
var form_url = 'http://<IP_ADDRESS>/server.php';
var win = Ti.UI.createWindow({
layout : 'vertical',
backgroundColor : '#fff'
});
var txtTitle = Ti.UI.createTextField({
top : '80dp',
value : 'My Photo Title'
});
win.add(txtTitle);
var anImageView = Ti.UI.createImageView({
image : 'images/flower.jpg',
width : 50,
height : 50,
});
anImageView.addEventListener('load', function() {
Ti.API.info('Image loaded!');
});
win.add(anImageView);
var btnSubmit = Ti.UI.createButton({
title : 'Submit'
});
btnSubmit.addEventListener('click', function(e) {
// Send with HTTPClient
var c = Ti.Network.createHTTPClient({
onload : function() {
Ti.API.info(this.responseText);
Ti.API.info("TEXT: " + this.responseText);
json = JSON.parse(this.responseText);
Ti.API.info('json' + json);
},
onerror : function(e) {
Ti.API.info("STATUS: " + this.status);
Ti.API.info("TEXT: " + this.responseText);
Ti.API.info("ERROR: " + e.error);
},
timeout : 50000
});
c.enableKeepAlive = false;
c.open('POST', form_url);
c.send(Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "/images/flower.jpg"));
});
win.add(btnSubmit);
win.open();
Tried with the latest master build, couldn't reproduce the issue. Here is the sample I tried, make sure that the image path is updated var form_url = 'http://www.w3schools.com/ajax/demo_post.asp'; var win = Ti.UI.createWindow({ layout : 'vertical', backgroundColor : '#fff' }); var btnSubmit = Ti.UI.createButton({ title : 'Submit' }); btnSubmit.addEventListener('click', function(e) { // Send with HTTPClient var c = Ti.Network.createHTTPClient(); c.onload = function() { Ti.API.info(this.responseText); Ti.API.info("TEXT: " + this.responseText); }; c.onerror = function(e) { Ti.API.info("STATUS: " + this.status); }; c.enableKeepAlive = false; c.open('POST', form_url); c.send(Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "/goofy.png")); }); win.add(btnSubmit); win.open();
Closing due to inactivity. If this issue still exists, please raise a new ticket.