NativeScript / nativescript-background-http

Background Upload plugin for the NativeScript framework
Apache License 2.0
101 stars 50 forks source link

[Upload Video] Error trying to upload video #191

Closed relez closed 5 years ago

relez commented 5 years ago

Hi there, I am trying to upload a video using nativescript-background-http. I am also using nativescript-mediafilepicker plugin to select the video and get the path of the file and pass it to the uploader. My code looks like this:

let allowedVideoQualities = [];
 if (app.ios) {
     allowedVideoQualities = [AVCaptureSessionPreset1920x1080, AVCaptureSessionPresetHigh]; 
}
let options: VideoPickerOptions = {
    android: {
        isCaptureMood: false, // if true then camera will open directly.
        isNeedCamera: true,
        maxNumberFiles: 1,
        isNeedFolderList: true,
        maxDuration: 20,
    },
    ios: {
        isCaptureMood: false, // if true then camera will open directly.
        videoMaximumDuration: 10,
        allowedVideoQualities: allowedVideoQualities
    }
};

let mediafilepicker = new Mediafilepicker(); 
mediafilepicker.openVideoPicker(options);

mediafilepicker.on("getFiles", (res) => {
    let results = res.object.get('results');
    let fileArr = results[0].file.split("/"); //Get the filename
    let session = bghttp.session("video-upload");
    let headers = parameters.Headers;
    headers["Content-Type"] = "application/octet-stream";
    headers["File-Name"] = fileArr[fileArr.length - 1];

    let request = {
        url: parameters.UploadURL,
        method: "POST",
        headers: {param1: "param1"},
        description: JSON.stringify(parameters.Headers)
     };
     let task = session.uploadFile(results[0].file, request);

     task.on("progress", onUploadProgress);
     task.on("error", onUploadError);
     task.on("complete", onUploadCompleted);
});

function onUploadProgress(e) {
    console.log("Uploading...");
}

function onUploadError(e) {
    console.log(e.responseCode);
    console.log(e.response);
}

function onUploadCompleted(e) {
    console.log("Completed...");
}

The responseCode I get is -1 and response as NULL. Any idea what could be happening? The video is only 14 seconds which is not too big.

Thanks!

VladimirAmiorkov commented 5 years ago

Hi @relez ,

Can you share with my the details of your setup:

relez commented 5 years ago

Hi @VladimirAmiorkov, I am testing on iOS, I havent tried Android yet.

I hope this helps!

VladimirAmiorkov commented 5 years ago

Hi @relez ,

Thank you for providing the additional information. I tried to reproduce this issue in this repository demo application but to no avail. Uploading an .m4v file was correctly uploaded to the "server" that is started in the demo app.

Can you send us an sample project that reproduces this issue or change the demo code in a way that it reproduces it and share it with us via a fork or directly by code snippet.

relez commented 5 years ago

Hi again, I have prepared a sample proyect, I hope it helps.

https://github.com/relez/ns-video-upload-ng.git

Thanks!

tbozhikov commented 5 years ago

Hi @relez, thank you for the sample project! The issue you are hitting inside is iOS, disabling all unsecured HTTP traffic. All you need is to add the following code to the Info.plist file in [the app]/App_Resources/iOS:

        <key>NSAppTransportSecurity</key>
        <dict>
            <key>NSAllowsArbitraryLoads</key>
            <true/>
        </dict>

Have in mind that this is OK for testing. For production, however, it is best to use services using https. You can see the same done in the demo project of the plugin. Hope this helps!

elena-p commented 5 years ago

closing due to inactivity