PritisD
September 23, 2016, 7:49am
1
Hi
I am developing an chat application using SignalR and Web Api. In this chat app I was trying to send the Images from
photo gallery and Camara from IonicActionSheet. I know that $cordovaDevice, $cordovaFile plugin are available.
my question is that Can I use <input type='file'/>
in $ionicActionSheet so that I can transfer the bytes of file to our web api.
Or any other way to implement such fuctionality
PritisD
September 28, 2016, 5:42am
2
Is any kind of reply by some one
hey there --> no need for type file.
You can create a Form in your Javascript:
var form = new FormFata();
form.append("NAME", FILE_PATH);
after that you need the cordova-file-transfer plugin and send your formdata to your backend.
PritisD
September 28, 2016, 7:14am
4
thanks for reply.
self.addMedia = function (type) {
self.addImage(type);
}
self.addImage = function (type) {
//$scope.hideSheet();
self.saveMedia(type).then(function () {
$scope.$apply();
});
}
self.optionsForType = function (type) {
var source;
switch (type) {
case 0:
source = Camera.PictureSourceType.CAMERA;
break;
case 1:
source = Camera.PictureSourceType.PHOTOLIBRARY;
break;
}
return {
quality: 90,
destinationType: Camera.DestinationType.DATA_URL,
sourceType: source,
allowEdit: false,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
saveToPhotoAlbum: false,
correctOrientation: true
};
}
self.saveMedia = function (type) {
return $q(function (resolve, reject) {
var options = self.optionsForType(type);
$cordovaCamera.getPicture(options).then(function (imageBase64) {
self.addImages(imageBase64);
});
})
}
var images=[];
self.addImages = function (files) {
var formdata = new FormData();
for (var i = 0; i < files.length; i++) {
formdata.append("file" + i, files[i]);
$scope.FileName = $scope.files[i].name;
images.push(uplodedFile);
}
};
here I am not getting the file in addImages() so that I can transfer it to back end.