diff --git a/libresapi/src/api/ApiServerLocal.cpp b/libresapi/src/api/ApiServerLocal.cpp index d55d1e5cc..5d89ed2d0 100644 --- a/libresapi/src/api/ApiServerLocal.cpp +++ b/libresapi/src/api/ApiServerLocal.cpp @@ -105,9 +105,17 @@ readPath: resource_api::Request req(reqJson); req.mMethod = reqMeth; req.setPath(reqPath); - std::string resultString = mApiServer->handleRequest(req); - mLocalSocket->write(resultString.c_str(), resultString.length()); + + // Need this idiom because binary result may contains \0 + std::string&& resultString = mApiServer->handleRequest(req); + QByteArray rB(resultString.data(), resultString.length()); + + // Dirty trick to support avatars answers + if(rB.contains("\n") || !rB.startsWith("{") || !rB.endsWith("}")) + mLocalSocket->write(rB.toBase64()); + else mLocalSocket->write(rB); mLocalSocket->write("\n\0"); + mState = WAITING_PATH; /* Because QLocalSocket is SOCK_STREAM some clients implementations diff --git a/retroshare-qml-app/src/ApiImageExample.qml b/retroshare-qml-app/src/ApiImageExample.qml new file mode 100644 index 000000000..cc7bd724d --- /dev/null +++ b/retroshare-qml-app/src/ApiImageExample.qml @@ -0,0 +1,43 @@ +/* + * RetroShare Android QML App + * Copyright (C) 2017 Gioacchino Mazzurco + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import QtQuick 2.7 + + +Rectangle +{ + color: "red" + + Image + { + id: testImg + height: 300 + width: 300 + } + + Component.onCompleted: + { + rsApi.request( + "/peers/d441e8890164a0f335ad75acc59b5a49/avatar_image", + "", setImgCallback ) + } + function setImgCallback(par) + { + testImg.source = "data:image/png;base64," + par.response + } +}