I am trying to upload a photo using ACS, but I am getting some runtime error.
Here is the code that I am using:
var image;
function uploadPhoto(){
Titanium.Media.openPhotoGallery({
success: function(e){
// alert(e.mediaType);
if(e.mediaType == Ti.Media.MEDIA_TYPE_PHOTO){
image = e.media;
alert(image);
Cloud.Photos.create({
photo: Titanium.Filesystem.getFile(image)
}, function(e){
if(e.success){
var photo = e.photos[0];
alert('Success:\n' +
'id: ' + photo.id + '\n' +
'filename: ' + photo.filename + '\n' +
'size: ' + photo.size,
'updated_at: ' + photo.updated_at);
}else{
alert('Error:\n' +
((e.error && e.message) || JSON.stringify(e)));
alert("Code: "+e.code);
}
});
}
},
cancel: function(){
},
error: function(err){
alert("ERROR: "+err);
},
mediaTypes:[Ti.Media.MEDIA_TYPE_PHOTO]
});
}
I am running on Android device and when I try to upload any image, I am getting the following error:
Error: Invalid photo file attachment
Code: 400
Can anyone tell me the solution?
Thanks! :)
this line
photo: Titanium.Filesystem.getFile(image)
should just be
photo: image
Related
I am developing a SAPUI5-App. Is there a way to show all errors directly to the customer without having to put a try-catch-block into every callback of sapui5? He will use my app in a mobile device and wouldn´t be able to see the log.
I tried already the following code:
<script type="text/javascript">
window.onerror = function(msg, url, line, col, error) {
var extra = !col ? '' : '\ncolumn: ' + col;
extra += !error ? '' : '\nerror: ' + error;
alert("Error: " + msg + "\nurl: " + url + "\nline: " + line + extra);
return false; //true = suppress error alert
};
window.addEventListener("error", handleError, true);
function handleError(evt) {
if (evt.message) {
alert("error: "+evt.message +" at linenumber: "+evt.lineno+" of file: "+evt.filename);
} else {
alert("error: "+evt.type+" from element: "+(evt.srcElement || evt.target));
}
}
jQuery.sap.log.addLogListener({
onLogEntry : function(oLogEntry) {
if(oLogEntry.level == '1'){
alert(oLogEntry.details + ' - '+oLogEntry.message);
}
}});
</script>
But I like to actually copy the error-message from the log into an alert for the customer, so he can send me screenshots of the error in his device.
All my attempts did not show enough information or didn´t fire on every error in the console-log.
I've been trying to get Android push notifications working for my app for a little while now (iOS already completed) and have everything sorted out besides just getting the notification to actually show up on the Android device.
Registering the device id's, and pushing to the GCM server all seem to be working fine, but when I test what the message in the response back from GCM is returning I keep getting undefined.
All responses when pushing the message to GCM are success, correct device id's, a message id associated with it etc. Anyone able to point me in the right direction? Below you will see the code snippet with just a sample "alert" being used to display what is coming back that will end up being used as the notification in the "push".
This alert
alert('message = ' + e.message + ' payload message: ' + e.payload.message +
' e payload msgcnt: ' + e.payload.msgcnt + ' e.msg: ' + e.msg);
doesn't seem to be getting anything back to display the push.
function onDeviceReady() {
console.log('deviceready');
try {
pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android' || device.platform == 'amazon-fireos') {
console.log('PN register');
pushNotification.register(successHandler, errorHandler, {
"senderID": "177718756870",
"ecb": "onNotification"
}); // required!
console.log('after PN register');
} else {
console.log('PN register');
pushNotification.register(tokenHandler, errorHandler, {
"badge": "true",
"sound": "true",
"alert": "true",
"ecb": "onNotificationAPN"
}); // required!
console.log('after PN register');
}
}
catch (err) {
txt = "There was an error on this page.\n\n";
txt += "Error description: " + err.message + "\n\n";
console.log("ERROR", txt);
}
}
var pushNotification;
// handle GCM notifications for Android
window.onNotification = function(e) {
console.log('EVENT RECEIVED ' + e.event)
console.log("regID BEFORE CHECKS = " + e.regid);
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0)
{
console.log("regID = " + e.regid);
var data =
{
'device_id': e.regid,
'platform': device.platform,
'os_version': device.version,
'app_version': lawnmowerConfig.versionString,
'device_model': device.model
};
localStorage.setItem('push_data', JSON.stringify(data));
}
break;
case 'message':
console.log('Inside case message: ' + e.regid)
if (e.foreground)
{
// Add something to play a sound once working
}
else
{
if (e.coldstart) {
console.log("coldstart");
}
else {
console.log("not coldstart");
}
}
alert('message = ' + e.message + ' payload message: ' + e.payload.message + ' e payload msgcnt: ' + e.payload.msgcnt + ' e.msg: ' + e.msg);
break;
case 'error':
alert('GCM error = ' + e.msg);
break;
default:
// Testing using these alerts instead
alert('An unknown GCM event has occurred');
break;
}
};
function tokenHandler (result) {
console.log('push token handler');
console.log(result);
var data =
{
'device_id': result,
'platform': device.platform,
'os_version': device.version,
'app_version': lawnmowerConfig.versionString,
'device_model': device.model
};
localStorage.setItem('push_data', JSON.stringify(data));
}
function successHandler (result) {
console.log('success handler push success');
console.log("result: " + result);
}
function errorHandler (error) {
console.log('push error');
}
document.addEventListener('deviceready', onDeviceReady, true);
Registering the device id's, and pushing to the GCM server all seem to be working fine, but when I test what the message in the response back from GCM is returning I keep getting undefined.
It means that when you are testing "what the message .... is" you are referencing a variable not yet defined. In this line:
alert('message = ' + e.message + ' payload message: ' + e.payload.message +
' e payload msgcnt: ' + e.payload.msgcnt + ' e.msg: ' + e.msg);
there is no variable e.message. The data that you send from your server is attached to e.payload and value of e.event is set to message. I think your problem can be solved if you remove e.message. Something like:
alert('event = ' + e.event + ' payload message: ' + e.payload.message +
' e payload msgcnt: ' + e.payload.msgcnt + ' e.msg: ' + e.msg);
Note To detect variable issues (scope and/or declaration), debug one variable at a time. This will help you to precisely identify a problem and trace it to its origin.
I would advise you to use
alert("Payload message: " + e.payload.message);
How can i see javascript errors from within a Phonegap App?
Currently I am trying to use this:
window.onerror = function(msg, url, linenumber) {
console.error('Type: ' + typeof msg + '\nError message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber);
return true;
};
But nothing shows up on screen or in weinre I am using.
I tried the following code. I want to record video in background and store in SD card. I don't want to do manual start recording and stop. Is it possible to record video with or without API in PhoneGap.
I want record video in background
<html>
<head>
<title>Capture Video</title>
<script type="text/javascript" charset="utf-8" src="js/cordova.js"></script>
<script type="text/javascript" charset="utf-8" src="js/json2.js"></script>
<script type="text/javascript" charset="utf-8">
// A button will call this function
function captureVideo() {
// Launch device video recording application,
// allowing user to capture up to 3 video clips
alert("captureVideo");
var options = {
limit : 2,
duration : 10
};
navigator.device.capture.captureVideo(captureSuccess, captureError,
options);
}
// Called when capture operation is finished
function captureSuccess(
mediaFiles) {
alert("captureSuccess ");
var i, len;
alert(mediaFiles.length);
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}
// Called if something bad happens.
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
navigator.notification.alert(msg, null, 'Uh oh!');
}
// Upload files to server
function uploadFile(mediaFile) {
alert("uploadFile");
var ft = new FileTransfer(), path = mediaFile.fullPath, name = mediaFile.name;
alert("path:" + path);
alert("name:" + name);
ft.upload(path, "http://my.domain.com/upload.php", function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
}, function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
}, {
fileName : name
});
}
</script>
</head>
<body>
<button onclick="captureVideo();">Capture Video</button>
<br>
</body>
</html>
document.addEventListener("deviceready", start_here, false);
function start_here(){captureVideo();}
function is called when ever app is launched and video records automatically.
and after sending again start recording...
function uploadFile(mediaFile) {
alert("uploadFile");
var ft = new FileTransfer(), path = mediaFile.fullPath, name = mediaFile.name;
alert("path:" + path);
alert("name:" + name);
ft.upload(path, "http://my.domain.com/upload.php", function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
}, function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
}, {
fileName : name
});
start_here; /*just call the instance. here is the change*/
}
Now you can record video with minimized app or even when screen is off by cordova\phonegap\ionic plugin
It's a fork, but main repo can't record video "in background" (in spite of the name).
When it starts, it automatically chooses, where to store video, by size of available space on SD and internal disk.
cordova plugin add cordova-backgroundvideo
var fileName = new Date().getTime() + '';
cordova.plugins.backgroundvideo.start(fileName, 'back', true, null, null);
cordova.plugins.backgroundvideo.stop(function (filePath) {
alert(filePath);
}, function (error) {
alert('Error ' + JSON.stringify(error));
}
);
I am trying to access the Appcelerator Titanium SDK for ACS after authenticating a user through Social Integrations. I am using the following code, which is copied line for line from the ACS Kitchen Sink example application, and I still cannot get it to work. The call to log the user in is successful, but the subsequent call to PhotoCollections API returns "404 - Failed to Authenticate user".
I am using oauth 3 legged authentication with the User Authentication Scheme set to Authorization Server. I have also tried other ACS APIs, without any luck. Please help! I've been stuck on this for 2 weeks now.
fb.addEventListener('login', function(e) {
if (e.success) {
Cloud.SocialIntegrations.externalAccountLogin({
type : 'facebook',
token : fb.accessToken
}, function(e) {
if (e.success) {
var user = e.users[0];
Cloud.PhotoCollections.create({
name : 'Party Pictures'
}, function(e) {
if (e.success) {
var collection = e.collections[0];
alert('Success:\n' + 'id: ' + collection.id + '\n' + 'name: ' + collection.name + '\n' + 'count: ' + collection.counts.total_photos + '\n' + 'updated_at: ' + collection.updated_at);
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
} else {
alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
}
});
}
});
Turns out that multiple posts online were wrong about the server configuration needed to do this. Make sure that your "User Authentication Scheme" is set to "API Server" and not "Authorization Server". It turned out to be that simple for me.