File Upload using HTTP Post (multi form data)

Hi all,

I have a problem in uploding image data to a API service using http POST method my is as below

$scope.add = function(file){
console.log(“called add”);
var fd = new FormData();
alert(file);
console.log(file);
fd.append(‘language’, ‘en’);
fd.append(‘apikey’, ‘XXXXXXX’);
fd.append(‘image’, file);
alert(fd);
$http.post(‘http://api.ocrapiservice.com/1.0/rest/ocr’,fd,{
transformRequest: angular.identity,
headers: { ‘Content-Type’:undefined}
})
.success(function(response) {
alert(response);
$scope.ReadData = response;
console.log(response);
})
.error(function(err) {
alert(“err”+err);
console.log(“err”+err);
});

}

the above code works fine from Chrome and retrieves the data perfectly, but in the mobile device it is not picking the file it seems, or something is wrong so always it errors as file data missing but alerts do pop correctly.

thanks for your help in advance…!!

any comments … welcome…!!

For mobile upload you need cordova file-transfer plugin ;).
https://github.com/apache/cordova-plugin-file-transfer/blob/master/doc/index.md
Greets, bengtler

Use ng-cordova

http://ngcordova.com/docs/#File

$cordovaFile
.uploadFile(server, filePath, options)
.then(function(result) {
  // Success! 
}, function(err) {
  // Error
}, function (progress) {
  // constant progress updates
});

Tq guys will try n let u know…

1 Like

btw: ng-cordova is the wrapper of ionic for file-transfer :wink:

1 Like

Hi ,
Did you tried file-transfer plugin?

Akşamdan beri uğraşıyorum servere resim yükleniyor ancak diğer post edilen verilere ulaşamıyorum aq

Merhaba! Lutfen Englishce yozunuz!