Browse file and upload file to server in ionic framework


#1

I have a problem i simply want to browse file and upload to server. file could be of any type ( jpg, pdf, doc etc). To achieve it i used filechooser to browse file and $cordovaFileTransfer while browsing file its not give exact file name.

$cordovaFileTransfer.upload(“http://54.186.104.222:5000/bulker/uploadmobilefile?accountId="+accountid+"&category=”+category, localuri).then(function(result) {
alert(JSON.stringify(result));
}, function(err) {
alert(JSON.stringify(err));
}, function (progress) {
$scope.uploadProgress = Math.ceil((progress.loaded / progress.total) * 100);
});


#2

Did you find an answer to this ?


#3

First resolve the native path & then give this path to FileTransfer plugin
fileChooser.open( function (fileUrl)
{
window.FilePath.resolveNativePath(fileUrl, function(filePath){
console.log(fileUrl);
$scope.$apply(function () { $scope.path = fileUrl; });
}, function(err){
$ionicPopup.alert({
title: ‘Error’,
template: err
});
});
},
function (error) { });

var options = { httpMethod: ‘POST’, chunkedMode : false, headers : { Connection: “close” }, framework: ‘Ionic’ };
var ft = new FileTransfer();
ft.upload($scope.path, encodeURI(configParamUrl+"/bulker/uploadpantan?emailId="+params.email+"&type=Pan"), win, fail, options); // This piece of line upload data.


#4

Yes i found & resolve.