使用wxHTTP Post请求上载wxImage
Upload wxImage with wxHTTP Post request
如何通过wxHTTP POST请求上传存储在wxImage或wxBitmap中的图像?我知道我可以用
wxImage::SaveFile (wxOutputStream &stream, wxBitmapType type) and
wxHTTP::SetPostBuffer (const wxString &contentType, const wxMemoryBuffer &data)
但我刚开始用cpp和wx。
您就快到了。缺少的部分是实现wxOutputStream
接口的某个类,然后可以使用SetPostBuffer()
方法发送其内容。
您可以在这里看到wxOutputStream
的所有实现。你好像在找wxMemoryOutputStream
。
因此,完整的代码部分应该是这样的:
wxMemoryOutputStream stream;
if (!myImage.SaveFile(stream, wxBITMAP_TYPE_PNG))
;// TODO: Handle error
SetPostBuffer("image/png", *stream.GetOutputStreamBuffer());
我就是这么做的。有点详细,但减去错误检查。。。成员变量是wxURL。
// ok now read the data into a buffer again
wxMemoryBuffer buf;
{
// don't have charBuf around for too long
wxFile f(someFileName);
char charBuf[f.Length()];
f.Read(charBuf, f.Length());
buf.AppendData(charBuf, f.Length());
}
// upload!
wxHTTP post;
post.SetPostBuffer("application/gzip", buf);
post.Connect(mDestUrl.GetServer()):
wxInputStream *iStream = post.GetInputStream(mDestUrl.GetPath() + "?" + mDestUrl.GetQuery());
// put result into stream
wxString res;
wxStringOutputStream oStream(&res);
iStream->Read(oStream);
wxLogDebug(TAG " server replied: " + res);
请注意,wxHttp不进行多部分上传。例如,在PHP中,您可以通过访问数据
$postdata = file_get_contents("php://input");
相关文章:
- 如何加载(或映射)文件部分的最大大小,但适合在Windows上的RAM
- 树莓上的 Libtorch 无法加载 pt 文件,但在 ubuntu 上工作
- 在另一台 PC 上执行程序时加载 SDL2 共享库时出错
- 0xc000007b Windows 上的 OpenCL 库的加载时间错误
- 在 win32 上生成 R 包:无法加载共享对象 (.dll)
- 如何使用 openGL 在屏幕上显示加载的纹理
- 在ARM上加载并存储重新排序
- 我在 IDA 或 dbg 或 olly 上看到的内存是否与我在 RAM 上实时加载的内存相同?
- 使用 dlopen 在 Mac 上加载 libjvm.dylib 时发出信号 SIGSEGV
- 使用CFBundleCreate在C++中的Mac上加载动态共享库(DLL)
- 将文件从 iOS 应用程序加载到 C++ 对象中/<iostream>iOS 上的问题
- 在 Linux 上,在 C++ 程序中,如何找到已加载共享库的路径?
- 无法在 macOS 上的 SDL 游戏中加载图像
- C++中的图像HTTP上载已损坏
- 使用HTTP上载文件.获取错误:-HttpSendReuest 12005
- QNetworkAccessManager多次上载失败
- 上载目录
- QNetworkAccessManager上载到本地FTP服务器
- 使用wxHTTP Post请求上载wxImage
- MFC文件上载