首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Octoprint API和GuzzleHttp上传文件

使用Octoprint API和GuzzleHttp上传文件
EN

Stack Overflow用户
提问于 2017-07-27 16:31:45
回答 1查看 331关注 0票数 1

我正在尝试通过octoprint的API上传一个gcode文件到我的octoprint。在此处链接到其文档:http://docs.octoprint.org/en/master/api/files.html#upload-file-or-create-folder

Octoprint以内部服务器错误响应。在检查它的日志文件时,我发现下面的行指示了octoprints上传函数中的问题

代码语言:javascript
复制
 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

代码语言:javascript
复制
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;
    }
}

我怎样才能改变我的请求,以防止这个错误的发生?

EN

回答 1

Stack Overflow用户

发布于 2017-07-28 23:28:49

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45345372

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档