Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Octoprint API和GuzzleHttp上载文件_Php_Guzzlehttp_Octoprint - Fatal编程技术网

Php 使用Octoprint API和GuzzleHttp上载文件

Php 使用Octoprint API和GuzzleHttp上载文件,php,guzzlehttp,octoprint,Php,Guzzlehttp,Octoprint,我正试图通过octoprint的API将gcode文件上传到octoprint。 此处链接到其文档: Octoprint响应一个内部服务器错误。 在检查它的日志文件时,我发现以下几行表示octoprints上载功能中存在问题 File "/home/pi/oprint/local/lib/python2.7/site-packages/OctoPrint-1.3.4-py2.7.egg/octoprin$ added_file = fileManager.add_file(FileDestin

我正试图通过octoprint的API将gcode文件上传到octoprint。 此处链接到其文档:

Octoprint响应一个内部服务器错误。 在检查它的日志文件时,我发现以下几行表示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'
我使用GuzzleHttp上传文件,调用api url/api/files/local

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;
    }
}

如何在Guzzle中更改请求以防止发生此错误?

问题是上传的文件没有正确的文件扩展名,而octoprint api在发送扩展名错误的文件时崩溃


据我的测试所示,octoprint api只能正确上载.gcode文件。

问题是上载的文件没有正确的文件扩展名,octoprint api在发送扩展名错误的文件时崩溃

据我的测试所示,octoprint api只能正确上传.gcode文件