curl-library
Uploading *.swf files.
Date: Tue, 10 Feb 2009 17:10:11 +0000
Hey!
I'm trying to use cURL to upload a *.swf file as part of
multipart/form-data but It doesn't work.
I'm able to upload other files (jpg, gif, png, dat) but *.swf doesn't
seem to reach the server - or even if it does get there, it's not
recognized as *.swf and discarded (I think).
Here's how I'm doing it:
[code]
curl = curl_easy_init();
if(curl)
{
std::string form1url =
misc::wstr2str(_ssd->wstrFormUrl);
curl_slist* headers = NULL;
curl_httppost* post = NULL;
curl_httppost* last = NULL;
headers = curl_slist_append(headers, "User-Agent:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322;
.NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)");
// title
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "game_name",
CURLFORM_COPYCONTENTS,
misc::wstr2str(_gpd->wsTitle).c_str(),
CURLFORM_END);
// max file size
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "MAX_FILE_SIZE",
CURLFORM_COPYCONTENTS, "100000000",
CURLFORM_END);
// thumbnail upload
std::wstring tmp =
AppManager::getSingletonPtr()->m_wstrGPdirectory;
tmp.append(L"\\");
tmp.append(_gpd->directoryTitle);
tmp.append(L"\\");
tmp.append(_gpd->directoryGJID);
tmp.append(L"\\100x100.jpg");
WIN32_FIND_DATA fd = {0};
HANDLE ff = FindFirstFile(tmp.c_str(), &fd);
if(fd.nFileSizeLow == 0)
{
tmp =
AppManager::getSingletonPtr()->m_wstrWorkingDirectory;
tmp.append(L"\\nopicture.jpg");
}
FindClose(ff);
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "img",
CURLFORM_FILE, misc::wstr2str(tmp).c_str(),
CURLFORM_CONTENTTYPE, "image/jpeg",
CURLFORM_END);
// end of thumbnail
// max file size
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "MAX_FILE_SIZE",
CURLFORM_COPYCONTENTS, "100000000",
CURLFORM_END);
// *.swf file to upload
tmp = AppManager::getSingletonPtr()->m_wstrGPdirectory;
tmp.append(L"\\");
tmp.append(_gpd->directoryTitle);
tmp.append(L"\\");
tmp.append(_gpd->directoryGJID);
tmp.append(L"\\");
tmp.append(_gpd->wsFileNameSWF);
WIN32_FIND_DATA fd2 = {0};
HANDLE ff2 = FindFirstFile(tmp.c_str(), &fd2);
if(fd2.nFileSizeLow == 0)
{
curl_slist_free_all(headers);
curl_formfree(post);
curl_easy_cleanup(curl);
return false;
}
FindClose(ff2);
curl_formadd(&post, &last,
CURLFORM_COPYNAME, "uploadedfile",
CURLFORM_FILE, misc::wstr2str(tmp).c_str(),
CURLFORM_CONTENTTYPE,
"application/x-shockwave-flash",
CURLFORM_END);
// end of *.swf file
std::string dataReceived; //tmp
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER,
this->errorBuffer);
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
curl_easy_setopt(curl, CURLOPT_URL, form1url.c_str());
curl_easy_setopt(curl, CURLOPT_HEADER, 1);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE,
cookiesFileName.c_str());
curl_easy_setopt(curl, CURLOPT_COOKIEJAR,
cookiesFileName.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,
io_url::writer);
curl_easy_setopt(curl, CURLOPT_WRITEDATA,
&dataReceived);
result = curl_easy_perform(curl);
curl_slist_free_all(headers);
curl_formfree(post);
curl_easy_cleanup(curl);
if (result != CURLE_OK)
return false;
else
return true;
}
[/code]
Any suggestions why the *.swf file (it's 10kb big) get's lost on the
way?
Cheers!
RobK
Received on 2009-02-10