[TIMOB-10036] iOS: HTTPClient does not support sending TiFile object as documentation states
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-01-16T23:21:24.000+0000 |
Affected Version/s | Release 2.0.2, Release 2.1.0, Release 2.1.3 |
Fix Version/s | Sprint 2012-15 Core, Release 3.0.0 |
Components | Core |
Labels | core, module_network, parity, qe-ios090112, qe-testadded |
Reporter | Max Stepanov |
Assignee | Max Stepanov |
Created | 2012-07-19T10:41:28.000+0000 |
Updated | 2017-03-14T04:40:11.000+0000 |
Description
When I run the below code on iOS, the image is not uploaded
After TIMOB-9590 fix the code below runs fine on Android, the image uploads successfully.
Repo Steps
1. Run the given code sample in your app.js 2. Click upload image button. 3. It will then display the URL to the uploaded image. 4. Copy URL and open in a browser.
var win1 = Titanium.UI.createWindow({
title:'Win 1',
backgroundColor:'#fff'
});
var img = Ti.UI.createImageView({
image: 'http://www.guestassist.net/images/logo.png',
width: 229,
height: 66,
top: 20
});
var b1 = Ti.UI.createButton({
title: 'upload image',
width: 200,
height: 40,
top: 100
});
b1.addEventListener('click', uploadImage);
var link = Ti.UI.createTextField({
value: '(url will show here)',
top: 160,
left: 10,
right: 10,
height: 60,
backgroundColor: 'white',
borderColor: '#dddddd',
borderWidth: 1,
font: {
fontSize: 13
}
});
win1.add(img);
win1.add(b1);
win1.add(link);
win1.open();
function uploadImage()
{
var http = Ti.Network.createHTTPClient({
onerror: function(e) {
if (JSON.stringify(e).search('The request timed out') >= 0)
{
Ti.API.info('timeout');
}
else
{
Ti.API.info('error');
}
},
onload: function(e) {
Ti.API.info('success!');
},
enableKeepAlive: false,
timeout: 360000
});
Ti.App.idleTimerDisabled = true;
var d = new Date();
var raw = d.getTime();
var filename = raw + '.png';
var f = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory + '/' + filename);
f.write(img.toBlob());
var uploadFile = Ti.Filesystem.getFile(Ti.Filesystem.tempDirectory, filename);
if (!uploadFile.exists()) { alert('file not found'); return false; }
var fileContents = uploadFile.read();
var curDate = 'Wed, 19 June 2011 10:00:00 -0500'; // hard coding date in AWS format for testing
var fileURL = 'https://s3.amazonaws.com/ga-testbucket/images/' + filename;
http.open('PUT', fileURL, false);
http.setRequestHeader('Content-Type', fileContents.mimeType);
if (Ti.Platform.osname != 'android')
{
http.setRequestHeader('Content-Length', uploadFile.size);
}
http.setRequestHeader('Host', 's3.amazonaws.com');
http.setRequestHeader('Date', curDate);
http.setRequestHeader('x-amz-acl', 'public-read');
http.send(uploadFile); // TiFile
alert('image uploaded!');
link.value = fileURL;
}
PR pending https://github.com/appcelerator/titanium_mobile/pull/2608
Environment used for verification - Tested with Titanium SDK: 2.2.0.v20120816212512 Tested with Titanium Studio: 2.1.1.201207271312 Device - iOS 5.1 simulator Machine OS - MAC 10.8
Reopening because this issue is still seen in the environment below : Titanium studio :2.1.2.201208301612 Xcode 4.4.1(build with iOS 5.1 SDK): SDK : 2.1.0 GA SDK : 2.1.1 GA SDK : 2.1.2 GA SDK : 2.1.3.v20120921190208 Xcode 4.5(build with iOS SDK 6.0) SDK : 2.1.3.v20120921190208 The image is not getting uploaded for IOS,whereas for android it works fine.
The fix went to 3.0.0.GA Please retest.
Closing ticket as fixed.