使用libcurl通过HTTP从内存(而不是磁盘)发送文件 [英] Sending a file from memory (rather than disk) over HTTP using libcurl
问题描述
我想通过用C ++编写的程序发送图片。 - OK
它的工作原理,但我想发送图片从预先载入的载体到一个变量char(你知道我的意思吗?首先,我将图片加载到一个变量,然后发送变量)原因现在我必须指定磁盘上的图片的路径。
I would like to send pictures via a program written in C + +. - OK It works, but I would like to send the pictures from pre-loaded carrier to a variable char (you know what I mean? First off, I load the pictures into a variable and then send the variable), cause now I have to specify the path of the picture on a disk.
我想使用curl库而不是通过exe编写这个程序在c ++中。延期。
我也发现了这样一个程序(我已经修改了一些)
I wanted to write this program in c++ by using the curl library, not through exe. extension. I have also found such a program (which has been modified by me a bit)
推荐答案
CURLFORM_PTRCONTENTS不是
CURLFORM_PTRCONTENTS is not the correct usage here, it will not create a file upload part.
而应该使用CURLFORM_BUFFER 从内存中已有的缓冲区发送图片。
Instead one should use CURLFORM_BUFFER to send an image from an already existing buffer in memory.
curl_formadd(&formpost,
&lastptr,
CURLFORM_COPYNAME, "send",
CURLFORM_BUFFER, "nowy.jpg",
CURLFORM_BUFFERPTR, data,
CURLFORM_BUFFERLENGTH, size,
CURLFORM_END);
这篇关于使用libcurl通过HTTP从内存(而不是磁盘)发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!