モバイルアプリケーション内でCordovaファイル転送アップロードを行うAngularサービスがあります。ファイルをメディアサーバーにアップロードしてオブジェクトを返します。私はmedia_response
プロパティにこのオブジェクトを渡そうとしていますが、私は運がありません - 私は間違っていますか?コーデックファイル転送内で角度サービス/ファクトリクラスのプロパティが更新されない
注意してください - 私はservice
とfactory
を使用してみましたし、まだ喜びを取得しないように思われている - $cordovaFileTransfer upload
ブロック内のものは、いくつかの奇妙な理由でクラスのプロパティに渡されていません。
私は、オブジェクトが、メディアサーバから返されたデータ変数と同じ出力でmedia_response
を見ることを期待していますが、それはno response
私が期待される応答が届かない理由を任意のアイデア言いますか?応答
UploadService.media_response in the controller should be an object to match the console.log(data)
//実際の応答
UploadService.media_response is the string 'no response'
//アップロードサービス
期待//
abcdServices.service('UploadService', function($http, $localStorage, $location, $q, $rootScope, $cordovaFileTransfer) { var UploadService = function() { this.upload_in_progress = false; this.progress = 0; this.media_response = ''; }; UploadService.prototype.cordovaFileUpload = function (filename, url, targetPath) { this.upload_in_progress = true; this.media_response = 'no response'; var options = { id: new Date() . getTime() + filename, fileKey: "file", fileName: filename, chunkedMode: false, mimeType: "multipart/form-data", params : {'fileName': filename} }; $cordovaFileTransfer.upload(url, targetPath, options).then( function(result) { // Success! var data = JSON.parse(result.response); console.log('file uploaded - response:', data); // ALWAYS A OBJECT this.media_response = 'fake response2'; UploadService.media_response = 'fake response3'; if (angular.isDefined(data.id)) { angular.forEach(data, function(value, key) { // image[key] = value; }); // $scope.post.linkThumbnail = false; // $scope.post.video = ''; } else if (angular.isDefined(data.message)) { // $scope.uploadError = data.message; } else { } }, function(err) { }, function (progress) { // constant progress updates this.progress = parseInt(100 * progress.loaded/progress.total) + '%'; } ); }; return new UploadService();});
//コントローラ
UploadService.cordovaFileUpload(filename, url, targetPath, options);
console.log(UploadService); // to view in js console