我有在我的HTTP服务器上上传小.txt
个文件的代码:
#include <wininet.h>
#define BUF_SIZE 4096
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TStringList * list = new TStringList();
AnsiString Path = "";
if(OpenDialog1->Execute()) {
Path = "filename=\""+OpenDialog1->FileName+"\"";
list->LoadFromFile(OpenDialog1->FileName);
}
char data[BUF_SIZE] = "";
static char hdrs[] = "Content-Type: multipart/form-data; boundary=---------------------------7d82751e2bc0858";
strcat(data,"-----------------------------7d82751e2bc0858");
strcat(data,"\n");
strcat(data,"Content-Disposition: form-data; name=\"files[]\"; ");
strcat(data,Path.c_str());
strcat(data,"\n");
strcat(data,"Content-Type: application/octet-stream");
strcat(data,"\n\n");
strcat(data,list->Text.c_str());
strcat(data,"\n");
strcat(data,"-----------------------------7d82751e2bc0858");
strcat(data,"\n");
strcat(data,"Content-Disposition: form-data; name=\"user\"");
strcat(data,"\r\n\r\n");
strcat(data,"username");
strcat(data,"\r\n");
strcat(data,"-----------------------------7d82751e2bc0858");
strcat(data,"\n");
HINTERNET hSession = InternetOpen("MyAgent",INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
HINTERNET hConnect = InternetConnect(hSession, "localhost",INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
HINTERNET hRequest = HttpOpenRequest(hConnect, "POST", "new_upltest.php", NULL, NULL, NULL, 0, 1);
HttpSendRequest(hRequest, hdrs, strlen(hdrs), data, strlen(data));
delete list;
}
它工作正常,但现在我需要上传大文件(超过70-100 mb),可以是图像(.jpg,.png,.bmp)和其他文档类型(.pdf,.docx,等)。
是否可以使用此代码解决我的任务?我会对每个建议表示感谢......
P.S。我的IDE是C ++ Builder 6,但我认为没关系。