Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7504747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:40:28+00:00 2026-05-29T21:40:28+00:00

I got iphone/ipad to work fine with the Titanium.Media.showCamera() function. Which is great. However

  • 0

I got iphone/ipad to work fine with the Titanium.Media.showCamera() function. Which is great.

However the same code doesn’t work on android like I expect. So I did some research and came up with this code below. The code itself works up to uploading the video. I can record, click save, but when it comes time to upload to my server, I get no communication error and on the server itself, I see no data in the POST or FILES array. The code below executes on the onclick button. I give part of the code since everything works except this. What gives?

button2.addEventListener('click', function() {
    // http://developer.android.com/reference/android/provider/MediaStore.html
    var intent = Titanium.Android.createIntent({ action: 'android.media.action.VIDEO_CAPTURE' });
    Titanium.Android.currentActivity.startActivityForResult(intent, function(e) {
        if (e.error) {
            Ti.UI.createNotification({
                duration: Ti.UI.NOTIFICATION_DURATION_LONG,
                message: 'Error: ' + e.error
            }).show();
        } else {
            if (e.resultCode === Titanium.Android.RESULT_OK) {
                var dataUri = e.intent.data;

                Titanium.Media.saveToPhotoGallery(dataUri);


                var xhr = Titanium.Network.createHTTPClient({enableKeepAlive:false});
                xhr.open('POST', 'http://someserver.com/upload.php');
                xhr.setRequestHeader("enctype", "multipart/form-data");
                xhr.setRequestHeader('Cache-Control', 'no-cache');
                xhr.onerror = function(e) {
                    alert(e.error);
                };
                xhr.onload = function() {
                    var data = JSON.parse(this.responseText);
                    if(data.FILE)
                        alert('File: '+data.FILE);
                    else
                        alert(this.responseText);
                };

                var fileData = Titanium.Filesystem.getFile(dataUri);
                var fileContent = fileData.read();
                xhr.send({video: fileContent});
            } else {
                Ti.UI.createNotification({
                    duration: Ti.UI.NOTIFICATION_DURATION_LONG,
                    message: 'Canceled/Error? Result code: ' + e.resultCode
                }).show();
            }
        }
    });
});

Also if you’re interested in the php code, here it is:

<?php

file_put_contents('output.txt', print_r($_POST, true)."\n".print_r($_FILES, true));

if(empty($_FILES['video']))
        die('invalid');

@move_uploaded_file($_FILES['video']['tmp_name'], $_FILES['video']['name']);
echo json_encode(array('FILE' => $_FILES['video']['name']));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:40:29+00:00Added an answer on May 29, 2026 at 9:40 pm

    Okay figured it out. The issue is the file is a uri, and the code doesn’t read uri on the file system. With that said, you’ll have to copy the file to a new file and then use that new file to upload to a server.

    The solution below works for me:

    button2.addEventListener('click', function() {
        // http://developer.android.com/reference/android/provider/MediaStore.html
        var intent = Titanium.Android.createIntent({ action: 'android.media.action.VIDEO_CAPTURE' });
        Titanium.Android.currentActivity.startActivityForResult(intent, function(e) {
            if (e.error) {
                Ti.UI.createNotification({
                    duration: Ti.UI.NOTIFICATION_DURATION_LONG,
                    message: 'Error: ' + e.error
                }).show();
            } else {
                if (e.resultCode === Titanium.Android.RESULT_OK) {
                    var dataUri = e.intent.data;
    
    
    
    
                    var xhr = Titanium.Network.createHTTPClient({enableKeepAlive:false});
                    xhr.open('POST', 'http://something.com/video/uploader.php');
                    xhr.setRequestHeader("enctype", "multipart/form-data");
                    xhr.setRequestHeader('Cache-Control', 'no-cache');
                    xhr.onerror = function(e) {
                        alert(e.error);
                    };
                    xhr.onload = function() {
                        var data = JSON.parse(this.responseText);
                        if(data.FILE)
                            alert('File: '+data.FILE);
                        else
                            alert(this.responseText);
                    };
    
                    var source = Ti.Filesystem.getFile(dataUri);
                    var fileData = Ti.Filesystem.getFile('appdata://sample.3gp');
                    // note: source.exists() will return false, because this is a URI into the MediaStore.
                    // BUT we can still call "copy" to save the data to an actual file
                    source.copy(fileData.nativePath);
                    Titanium.Media.saveToPhotoGallery(fileData);
                    if(fileData.exists())
                    {
                        var fileContent = fileData.read();
                        if(fileContent)
                            xhr.send({video: fileContent});
                        else
                            alert('Did not get any data back from file content');
                    }
                    else
                        alert('Did not get a file data for : '+dataUri);
                } else {
                    Ti.UI.createNotification({
                        duration: Ti.UI.NOTIFICATION_DURATION_LONG,
                        message: 'Canceled/Error? Result code: ' + e.resultCode
                    }).show();
                }
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an iPhone project and my english Localizable.strings suddenly doesn't work anymore. I
I've got an iPhone app and an iPad app, both running the same web
On an iPhone App, I've got a custom keyboard which works like the standard
I've got a universal ipad/iphone app that allows the user to watch a video,
I have the following code which worked fine before I implemented jquery mobile. Now,
I'm working on an iPhone/iPad application and I've got an unpleasant issue. There is
I got a book for iPad programming and there is source code in a
I have an app that uses NASA live TV stream for the iphone/ipad which
I have to builds of the same app for iphone and ipad, both are
I've got an iPhone project using liblo (liblo.sourceforge.net). My project's been working fine in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.