#include <stdio.h>
#include <string.h>
#include <zlib.h>
int compress_gzfile_puts(const char* filename, char* source)
{
gzFile zp;
zp = gzopen(filename, "w9");
if(zp == NULL){
fprintf(stderr, "gzopen error\n");
return -1;
}
gzwrite(zp, source, strlen(source));
gzclose(zp);
return 0;
}
static bool httpUploadGzipFile(const char* filename, char* source)
{
CURLcode res;
long statusCode= -1;
struct stat file_info;
FILE *fd;
//gzip圧縮
compress_gzfile_puts(filename, source);
//open file to upload
fd = fopen(filename, "rb");
//can't continue
if(!fd) {
return false;
}
//to get the file size
if(fstat(fileno(fd), &file_info) != 0) {
return false;
}
//Post
curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(m_curl, CURLOPT_POST, 1);
/*圧縮じゃない方法でデータをサーバー送る
curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, postthis);
curl_easy_setopt(m_curl, CURLOPT_POSTFIELDSIZE, strlen(postthis));
*/
//tell it to "upload" to the URL
curl_easy_setopt(m_curl, CURLOPT_UPLOAD, 1L);
//set where to read from (on Windows you need to use READFUNCTION too)
curl_easy_setopt(m_curl, CURLOPT_READDATA, fd);
//and give the size of the upload (optional)
curl_easy_setopt(m_curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)file_info.st_size);
//Set the default value: strict certificate check please
curl_easy_setopt(m_curl, CURLOPT_SSL_VERIFYPEER, 0L);
//実行
curl_easy_perform(m_curl);
res = curl_easy_getinfo( m_curl, CURLINFO_RESPONSE_CODE, &statusCode);
if(res != CURLE_OK) {
return false;
}
return true;
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
00