2017-07-27 5 views
1

gcodeファイルをそのAPI経由でoctoprintにアップロードしようとしています。 ここにそのドキュメントへのリンク:http://docs.octoprint.org/en/master/api/files.html#upload-file-or-create-folderOctoprint APIとGuzzleHttpでファイルをアップロードする

Octoprintは内部サーバーエラーで応答します。

がどのように
public function printFile(Raspi $raspi,$file) { 
    $fileName = basename($file); 

    $result = $this->callAPIMethod($raspi, '/api/files/local', [ 
     'multipart' => [ 
      [ 
       'name'  => 'file', 
       'contents' => Storage::get($filePath), 
       'filename' => $fileName 
      ], 
      [ 
       'name'  => 'print', 
       'contents' => true, 
      ] 
     ] 
    ],"post"); 
    $raspi->status = "druckt"; 
    $raspi->save(); 
} 

private function callAPIMethod(Raspi $raspi,$apiPath,$commandParams,$method='get') { 
    $client = new Client(); 
    $apiKey = $raspi->key; 
    $params = [ 
     'headers' => [ 
      'X-API-Key' => $apiKey, 
     ] 
    ]; 
    if($commandParams != NULL) 
     $params = array_merge ($params, $commandParams); 
    switch($method) { 
     case "get":  
      return $client->get($raspi->ip.":".RaspiApiController::$APIPORT."/".$apiPath, $params); 
     break; 
     case "post":  
       return $client->post($raspi->ip.":".RaspiApiController::$APIPORT.$apiPath, $params); 
     break; 
     case "delete":  
      return $client->delete($raspi->ip.":".RaspiApiController::$APIPORT."/".$apiPath, $params); 
     break; 
     default: 
      return $client->get($raspi->ip.":".RaspiApiController::$APIPORT."/".$apiPath, $params); 
     break; 
    } 
} 

ローカル/ APIのURL/API /ファイルを呼び出して、私はファイルをアップロードするGuzzleHttpを使用しています私はoctoprintsで問題を示す次の行が関数

File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.3.4-py2.7.egg/octoprin$ 
added_file = fileManager.add_file(FileDestinations.LOCAL, futureFullPathInStorage, uploa$ 
File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.3.4-py2.7.egg/octoprin$ 
self._analysis_queue.dequeue(queue_entry) 
File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.3.4-py2.7.egg/octoprin$ 
if not entry.type in self._queues: 
AttributeError: 'NoneType' object has no attribute 'type' 

をアップロードしたそのログファイルをチェックする際に このエラーが発生しないように私のGuzzleでRequestを変更する必要がありますか?

答えて

0

問題は、アップロードされたファイルに正しいファイル拡張子がなく、octoprint APIが間違った拡張子のファイルを送信するとクラッシュしたということが判明しました。

私のテストで示されている限り、Octoprint APIによって.gcodeファイルのみが正しくアップロードされます。

関連する問題