2017-03-27 11 views
0

クライアント側(Ionic Framework)からPythonバックエンド(Flask)にイメージを送信しようとしています。何らかの理由で、私が理解しているエラーコード3が接続エラーですが、理由はわかりません。イメージをPythonバックエンドに送信する - Cordovaファイル転送

クライアント側のコード(AngularJS):

$scope.submit = function() { 
     if($scope.details.title === '' || $scope.details.price === '' || $scope.details.description === '' 
     || $scope.details.category === '') { 
      ionicSuperPopup.show("Error!", "Fill out the appropriate fields!", "error"); 
     } else if($scope.size !== 2) { 
      ionicSuperPopup.show("Error!", "You need to upload at least two images.", "error"); 
     } else { 
      /* Post item to server, wait for success, and present success post. */ 
      //ItemFactory.addItem($scope.details); 
      var url = 'http://127.0.0.1:5000/api/item/addItem'; 
      var name = $scope.details.images[0]; 
      var options = new FileUploadOptions(); 
      options.fileKey = 'image', 
      options.fileName = name, 
      options.chunkedMode = false, 
      options.mimeType = 'image/jpg', 
      options.params = { 'filename': name }; 
      options.headers = { 
       Connection: "close" 
      }; 

      var ft = new FileTransfer(); 
      ft.upload($scope.list[0], encodeURI(url), win, fail, options); 
     } /* End of 'else' */ 
    } /* End of 'submit' */ 

の$ scope.list [0]撮影した画像のimageURIが含まれています。

バックエンドのコード:

from flask_restful import reqparse, Resource 

    class Item(Resource): 
     parser = reqparse.RequestParser(bundle_errors=True) #All arguments must be present 

     def post(self): 
      Item.parser.add_argument('image', required=True, help="You need images.") 
      args = Item.parser.parse_args() 
      print("We have: {}".format(args)) 

は私が間違ってやっているものはありますか?私はすべてがカバーされているように感じるが、なぜ私はエラーコード3があるのか​​分からない。助けてくれてありがとう!

+0

なぜ、Connection close HTTPヘッダーを使用していますか? –

+0

この問題を解決する試みでした。しかし、私は実際に何が間違っているかを考え出しました。あなたはする必要があります: Item.parser.add_argument( 'file'、required = True、help = "イメージが必要です"、type = werkzeug.datastructures.FileStorage、location = 'files') – Zain

答えて

0

私は実際に問題を考え出しました。イメージはファイルのアップロードとしてロードする必要があり、これを行うにはwerkzeugのFileStorageを使用しました:

Item.parser.add_argument('file', required=True, help="You need image.", type=werkzeug.datastructures.FileStorage, location='files') 
関連する問題