我正在尝试使用 POCO::Net::HTMLForm 将图片上传到 appengine。请看下面的代码。我遇到的问题是图像数据没有发送。令牌和角色名称(其用于开源动作 rpg)传输没有任何问题。知道我可能做错什么吗?
提前致谢 :)
C++代码:
// prepare session
Poco::URI uri(backend_url + "/api/update_character_avatar");
Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
// prepare path
std::string path(uri.getPathAndQuery());
if (path.empty()) path = "/";
Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_POST, path);
Poco::Net::HTMLForm form;
form.add("token", sw_token);
form.add("charname", sw_charname);
Poco::Buffer<char> imgBuffer(mImgPtr->size());
mImgPtr->read(imgBuffer.begin(), imgBuffer.end()-imgBuffer.begin());
std::string s(imgBuffer.begin(), mImgPtr->size());
std::ostringstream out;
Poco::Base64Encoder b64enc(out);
b64enc.write(imgBuffer.begin(), imgBuffer.end()-imgBuffer.begin());
b64enc.close();
Poco::Net::StringPartSource *prtsrc = new Poco::Net::StringPartSource(out.str());
form.addPart("imagedata", prtsrc);
form.prepareSubmit(req);
std::ostream& send = session.sendRequest(req);
form.write(send);
// get response
Poco::Net::HTTPResponse res;
// print response
std::istream &is = session.receiveResponse(res);
std::ostringstream stream;
Poco::StreamCopier::copyStream(is, stream);
std::cout << stream.str() << std::endl;
应用引擎的 Python 处理程序:
class UpdateCharacterAvatarHandler(webapp2.RequestHandler):
def post(self):
token = self.request.get("token")
charname = self.request.get("charname")
imagedata = self.request.get("imagedata")
logging.error(self.request.body)
self.response.write("test")