locked
upload a captured image to server in background using javascript

    Question

  • dialog.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(

    function(file) {

    if(file) {

    varuploader = newWindows.Networking.BackgroundTransfer.BackgroundUploader();

    upload = uploader.createUpload(uri, file)

    This throws (Type mismatach exception). new file is capture image file handle from

    }

    });

    Any ideas.. why and what to do to upload a camera image using background upload to transfer a capture image or video using JavaScript windows 8?


    • Edited by al_jain Tuesday, June 25, 2013 7:21 PM
    Monday, June 24, 2013 3:50 PM

All replies

  • Hi,

    captureFileAsync returns a StorageFile, and createUpload requieres an IStorageFile which should work. I see that your "done" handler has a "function(file)" handler but you are passing a variable called newfile to createUpload, you should pass "file", not "newfile", I don't see "newfile" declared in your code.

    dialog.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(
    
    function(file) {
    
    if(file) {
    
    varuploader = newWindows.Networking.BackgroundTransfer.BackgroundUploader();
    
    upload = uploader.createUpload(uri, file);
    upload.startAsync().then(complete, error, progress);//use the handlers you see fit
    
    }
    
    });


    Tuesday, June 25, 2013 12:38 PM
  • That was my typo. In the code it is file only. But it doen't work. Just throws an expectation of type mismatch. 
    Tuesday, June 25, 2013 8:30 PM
  • Could it be that the URI you are using has an incorrect format? Are you uploading to a public server? An FTP? Skydrive?

    I'll try to repo this as soon as I get my hands on a notebook with a built in camera, but the code seems to be fine, should work in theory.

    Couple of things I would try:


    • Use the backgroundUploader to upload a local file instead of a captured one (to rule out possible stream issues)
    • If the above works, save the captured file locally and then open that file for the upload instead of using the captured file handler
    • Try another URI
    Wednesday, June 26, 2013 1:07 PM