我正在使用Ionic和Angular Framework开发应用程序。在我的应用程序中,我需要捕获视频并将其上传到服务器。为此,我使用media-capture plugin捕获视频,并使用file transfer plugin将其上传到服务器。
这里是我用来捕获并将其上传到远程服务器的代码:
// Capturing Video
captureVideo() {
let options: CaptureVideoOptions = { limit: 1 }
this.mediaCapture.captureVideo(options)
.then((videoData: MediaFile[]) => {
var i, path, len;
for (i = 0, len = videoData.length; i < len; i += 1) {
path = videoData[i].fullPath;
}
this.videoPath = path;
console.log(this.videoPath);
})
.catch((err: CaptureError) => err)
}
// Uploading Video
uploadVideo() {
var options: FileUploadOptions = {
fileKey: "videos",
fileName: 'sample.mp4',
chunkedMode: false,
mimeType: "video/mp4"
}
var params: any = {};
params.typeOfItemGroup = "SPACE";
params.itemGroupName = "Kitchen";
options.params = params;
console.log("options: ", options);
this.videoFileUpload = this.fileTransfer.create();
this.videoFileUpload.upload(this.videoPath, 'localhost:8081/api/v1/shield/camera/video/5e706f96b5587e5e6776614f', options)
.then((data) => {
console.log("Data: " + data);
})
.catch((err) => {
console.log("Error in upload: ", err);
});
}
我得到的错误是:click here
我无法确定代码:2错误。
对于后端,它可以正常工作,如下所示:click here
任何建议都将不胜感激。
谢谢,卡鲁姆里
不推荐使用文件传输插件。我建议您看看这篇文章,以了解上传文件的替代方法:https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html。
错误代码2是指无效的网址。您可以在文档中找到错误代码:https://github.com/apache/cordova-plugin-file-transfer/blob/master/README.md#constants