[TIMOB-9806] MobileWeb: Parity issue with HTTPClient send data that contains a blob
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Won't Fix |
Resolution Date | 2017-06-26T21:54:34.000+0000 |
Affected Version/s | Release 2.1.0 |
Fix Version/s | n/a |
Components | MobileWeb |
Labels | js, parity |
Reporter | Jeff English |
Assignee | Chris Barber |
Created | 2012-06-26T15:42:58.000+0000 |
Updated | 2018-04-04T23:20:26.000+0000 |
Description
Attempting to send data where one of the properties is a blob will fail when making an HTTP client request on MobileWeb. An example of this is manifested when trying to upload a photo to ACS.
This issue was identified when running the updated ti.cloud Anvil tests.
This works on iOS and Android platforms. If you examine the source code on iOS and Android you will notice that there is special handling for blob properties.
The following example demonstrates the issue:
var sessionID;
var apikey = '<YOUR API KEY HERE>';
var userid = '<YOUR USERID HERE>';
var password = '<YOUR PASSWORD HERE>';
var photoFileName = 'appcelerator.jpg'; // Replace with the name of an image file located in your Resources folder
var login = function() {
var data = {
login: userid,
password: password
}
var xhr = Ti.Network.createHTTPClient({
onerror: function(e) {
Ti.API.error("ERROR");
},
onload: function(e) {
Ti.API.info("LOGGED IN");
var json = this.responseText;
var data = JSON.parse(json);
if (data && data.meta) {
sessionID = data.meta.session_id;
createPhoto();
}
}
});
xhr.open("POST", "https://api.cloud.appcelerator.com/v1/users/login.json?key=" + apikey);
xhr.send(data);
}
var createPhoto = function() {
var data = {
photo: Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, photoFileName).read(),
suppress_response_codes: 'true',
};
var xhr = Ti.Network.createHTTPClient({
onerror: function(e) {
Ti.API.error("ERROR");
},
onload: function(e) {
Ti.API.info("CREATED");
Ti.API.info(this.responseText);
}
});
xhr.open("POST", "https://api.cloud.appcelerator.com/v1/photos/create.json?key=" + apikey + "&_session_id=" + sessionID);
xhr.send(data);
}
login();
The problem stems from Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, photoFileName).read() returning a Blob, which then invokes the Blob's toString() method. toString() on a blob will return a data uri with the binary image file base64 encoded. To fix it, we need to update the urlEncode function in Ti._.lang to check if the value is a binary Ti.Blob, then base64 decode it and then uri encode it.
Resolving as "Won't Fix" as MobileWeb has been deprecated.
Closing as will not fix.