|
Uploads are not directly supported by the http protocol. What you need to do is implement a server side mechanism to collect the data as delivered from the client in the body of the HTTP request and then deposit it as a file on the server somewhere. There are ASP components as well as ISAPI, CGI and script solutions to all of these if you look around. The actual client upload can be handled by wininet. Please see the MSDN for documentation on using wininet.
|
|
|
|
|
the demo file run perfect, but....
when i've tried to create a new workspace, and attach the two files(via "project->add to proyect-> files" mentioned on the .htm , and everything goes wrong. why is happening this?
i'm using Visual C++ 6.0 and the source downloaded from your site (v1.07)
hope you can help me
here's the error list
--------------------Configuration: Download - Win32 Debug--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
Download.cpp
DownloadDlg.cpp
HttpDownloadDlg.cpp
C:\Download\httpdownloaddlg.h(61) : error C2065: 'IDD_HTTPDOWNLOAD' : undeclared identifier
C:\Download\httpdownloaddlg.h(61) : error C2057: expected constant expression
C:\Download\httpdownloaddlg.h(86) : error C2061: syntax error : identifier 'HINTERNET'
C:\Download\httpdownloaddlg.h(88) : error C2061: syntax error : identifier 'HINTERNET'
C:\Download\httpdownloaddlg.h(89) : error C2061: syntax error : identifier 'HINTERNET'
C:\Download\httpdownloaddlg.h(90) : error C2061: syntax error : identifier 'HINTERNET'
C:\Download\httpdownloaddlg.h(91) : error C2061: syntax error : identifier 'HINTERNET'
C:\Download\httpdownloaddlg.h(114) : error C2146: syntax error : missing ';' before identifier 'm_nPort'
C:\Download\httpdownloaddlg.h(114) : error C2501: 'INTERNET_PORT' : missing storage-class or type specifiers
C:\Download\httpdownloaddlg.h(114) : error C2501: 'm_nPort' : missing storage-class or type specifiers
C:\Download\httpdownloaddlg.h(115) : error C2146: syntax error : missing ';' before identifier 'm_hInternetSession'
C:\Download\httpdownloaddlg.h(115) : error C2501: 'HINTERNET' : missing storage-class or type specifiers
C:\Download\httpdownloaddlg.h(115) : error C2501: 'm_hInternetSession' : missing storage-class or type specifiers
C:\Download\httpdownloaddlg.h(116) : error C2146: syntax error : missing ';' before identifier 'm_hHttpConnection'
C:\Download\httpdownloaddlg.h(116) : error C2501: 'HINTERNET' : missing storage-class or type specifiers
C:\Download\httpdownloaddlg.h(116) : error C2501: 'm_hHttpConnection' : missing storage-class or type specifiers
C:\Download\httpdownloaddlg.h(117) : error C2146: syntax error : missing ';' before identifier 'm_hHttpFile'
C:\Download\httpdownloaddlg.h(117) : error C2501: 'HINTERNET' : missing storage-class or type specifiers
C:\Download\httpdownloaddlg.h(117) : error C2501: 'm_hHttpFile' : missing storage-class or type specifiers
To avoid this message, please put afxpriv.h in your PCH (normally stdafx.h)
C:\Download\HttpDownloadDlg.cpp(139) : error C2065: 'm_hInternetSession' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(140) : error C2065: 'm_hHttpConnection' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(141) : error C2065: 'm_hHttpFile' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(158) : error C2065: 'IDC_STATUS' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(159) : error C2065: 'IDC_TRANSFER_RATE' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(160) : error C2065: 'IDC_TIMELEFT' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(161) : error C2065: 'IDC_PROGRESS1' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(162) : error C2065: 'IDC_FILESTATUS' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(163) : error C2065: 'IDC_ANIMATE1' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(204) : error C2065: 'IDR_HTTPDOWNLOAD_ANIMATION' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(208) : error C2065: 'AfxParseURL' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(208) : error C2065: 'm_nPort' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(228) : error C2065: 'IDS_HTTPDOWNLOAD_OK_TO_OVERWRITE' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(249) : error C2065: 'IDS_HTTPDOWNLOAD_FAIL_FILE_OPEN' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(268) : error C2065: 'IDS_HTTPDOWNLOAD_FAIL_FILE_SEEK' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(289) : error C2065: 'IDS_HTTPDOWNLOAD_FILESTATUS' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(325) : error C2065: 'IDS_HTTPDOWNLOAD_PERCENTAGE' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(336) : error C2065: 'IDS_HTTPDOWNLOAD_BYTES' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(342) : error C2065: 'IDS_HTTPDOWNLOAD_KILOBYTES' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(348) : error C2065: 'IDS_HTTPDOWNLOAD_MEGABYTES' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(372) : error C2065: 'IDS_HTTPDOWNLOAD_OF' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(379) : error C2065: 'IDS_HTTPDOWNLOAD_SECONDS' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(390) : error C2065: 'IDS_HTTPDOWNLOAD_MINUTES' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(392) : error C2065: 'IDS_HTTPDOWNLOAD_MINUTES_AND_SECONDS' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(396) : error C2065: 'IDS_HTTPDOWNLOAD_TIMELEFT' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(426) : error C2065: 'IDS_HTTPDOWNLOAD_BYTESPERSECOND' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(432) : error C2065: 'IDS_HTTPDOWNLOAD_KILOBYTESPERSECOND' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(479) : error C2065: 'HINTERNET' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(479) : error C2146: syntax error : missing ')' before identifier 'hInternet'
C:\Download\HttpDownloadDlg.cpp(479) : error C2350: 'CHttpDownloadDlg::QueryStatusNumber' is not a static member
C:\Download\HttpDownloadDlg.cpp(479) : error C2059: syntax error : ')'
C:\Download\HttpDownloadDlg.cpp(480) : error C2143: syntax error : missing ';' before '{'
C:\Download\HttpDownloadDlg.cpp(480) : error C2447: missing function header (old-style formal list?)
C:\Download\HttpDownloadDlg.cpp(486) : error C2146: syntax error : missing ')' before identifier 'hInternet'
C:\Download\HttpDownloadDlg.cpp(486) : error C2350: 'CHttpDownloadDlg::QueryStatusCode' is not a static member
C:\Download\HttpDownloadDlg.cpp(486) : error C2059: syntax error : ')'
C:\Download\HttpDownloadDlg.cpp(487) : error C2143: syntax error : missing ';' before '{'
C:\Download\HttpDownloadDlg.cpp(487) : error C2447: missing function header (old-style formal list?)
C:\Download\HttpDownloadDlg.cpp(491) : error C2146: syntax error : missing ')' before identifier 'hInternet'
C:\Download\HttpDownloadDlg.cpp(491) : error C2350: 'CHttpDownloadDlg::QueryContentLength' is not a static member
C:\Download\HttpDownloadDlg.cpp(491) : error C2059: syntax error : ')'
C:\Download\HttpDownloadDlg.cpp(492) : error C2143: syntax error : missing ';' before '{'
C:\Download\HttpDownloadDlg.cpp(492) : error C2447: missing function header (old-style formal list?)
C:\Download\HttpDownloadDlg.cpp(505) : error C2039: 'InternetOpen' : is not a member of '`global namespace''
C:\Download\HttpDownloadDlg.cpp(505) : error C2065: 'InternetOpen' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(505) : error C2065: 'INTERNET_OPEN_TYPE_PRECONFIG' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(510) : error C2065: 'INTERNET_OPEN_TYPE_DIRECT' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(516) : error C2065: 'INTERNET_OPEN_TYPE_PROXY' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(529) : error C2065: 'IDS_HTTPDOWNLOAD_GENERIC_ERROR' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(541) : error C2039: 'InternetSetStatusCallback' : is not a member of '`global namespace''
C:\Download\HttpDownloadDlg.cpp(541) : error C2065: 'InternetSetStatusCallback' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(541) : error C2065: 'INTERNET_INVALID_STATUS_CALLBACK' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(558) : error C2039: 'InternetConnect' : is not a member of '`global namespace''
C:\Download\HttpDownloadDlg.cpp(558) : error C2065: 'InternetConnect' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(559) : error C2065: 'INTERNET_SERVICE_HTTP' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(566) : error C2065: 'IDS_HTTPDOWNLOAD_FAIL_CONNECT_SERVER' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(592) : error C2065: 'INTERNET_FLAG_RELOAD' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(592) : error C2065: 'INTERNET_FLAG_DONT_CACHE' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(592) : error C2065: 'INTERNET_FLAG_KEEP_CONNECTION' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(593) : error C2065: 'AFX_INET_SERVICE_HTTPS' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(593) : warning C4018: '==' : signed/unsigned mismatch
C:\Download\HttpDownloadDlg.cpp(594) : error C2065: 'INTERNET_FLAG_SECURE' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(594) : error C2065: 'INTERNET_FLAG_IGNORE_CERT_CN_INVALID' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(594) : error C2065: 'INTERNET_FLAG_IGNORE_CERT_DATE_INVALID' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(595) : error C2065: 'HttpOpenRequest' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(620) : error C2039: 'HttpSendRequest' : is not a member of '`global namespace''
C:\Download\HttpDownloadDlg.cpp(620) : error C2065: 'HttpSendRequest' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(635) : error C2065: 'IDS_HTTPDOWNLOAD_INVALID_SERVER_RESPONSE' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(641) : error C2065: 'HTTP_STATUS_PROXY_AUTH_REQ' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(641) : warning C4018: '==' : signed/unsigned mismatch
C:\Download\HttpDownloadDlg.cpp(641) : error C2065: 'HTTP_STATUS_DENIED' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(641) : warning C4018: '==' : signed/unsigned mismatch
C:\Download\HttpDownloadDlg.cpp(649) : error C2039: 'InternetReadFile' : is not a member of '`global namespace''
C:\Download\HttpDownloadDlg.cpp(649) : error C2065: 'InternetReadFile' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(654) : warning C4018: '==' : signed/unsigned mismatch
C:\Download\HttpDownloadDlg.cpp(660) : error C2065: 'InternetSetOption' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(668) : warning C4018: '==' : signed/unsigned mismatch
C:\Download\HttpDownloadDlg.cpp(674) : error C2065: 'INTERNET_OPTION_USERNAME' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(676) : error C2065: 'INTERNET_OPTION_PASSWORD' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(684) : error C2039: 'InternetErrorDlg' : is not a member of '`global namespace''
C:\Download\HttpDownloadDlg.cpp(684) : error C2065: 'InternetErrorDlg' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(684) : error C2065: 'ERROR_INTERNET_INCORRECT_PASSWORD' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(684) : error C2065: 'FLAGS_ERROR_UI_FILTER_FOR_ERRORS' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(685) : error C2065: 'FLAGS_ERROR_UI_FLAGS_GENERATE_DATA' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(685) : error C2065: 'FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(685) : error C2065: 'ERROR_INTERNET_FORCE_RETRY' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(688) : error C2065: 'HTTP_STATUS_OK' : undeclared identifier
C:\Download\HttpDownloadDlg.cpp(688) : fatal error C1003: error count exceeds 100; stopping compilation
Generating Code...
Error executing cl.exe.
Download.exe - 102 error(s), 5 warning
|
|
|
|
|
Read the documentation which comes with the download in the htm file. You need to include wininet.h in your project as well as copy over the specified resources. Nothing magic.
|
|
|
|
|
Hi.
How to ignore global offline mode? I use InternetSetOption() to set INTERNET_OPTION_IGNORE_OFFLINE option, but get failed. ???
|
|
|
|
|
Hey there
I'm pretty sure the reason is because I have not created the resources properly. I've gone to the website and downloaded the latest version v1.16, but it does not give a detailed account on how to actually make it work.
I realize that I need to create the HTTP DOWNLOAD dialog, but the problem is I do not know how to simply copy over from the sample project into my project. I've tried manually creating them, but another thing I'm running into is that I can not seem to find the (Text Control) Istat Editor (for the time left boxes, etc). I've looked and looked but can't find it so I can't create one. (But, I can compile the sample app just fine and it works fine)
Does anyone know how I can simply copy a dialog and all of the details of that dialog into a new project?
Also, I saw a post saying that wininet.lib needs to be included. Does this go in "command line -> Additional options?". Currently, I have one .LIB in there now, how should I separate them, etc lib101.lib;wininet.lib ... with a colon, comma, etc?
TIA
|
|
|
|
|
1. how to actually make it work: Yes, it does. Just read the HTML file included in the download.
2. There is no need to manually create the sources, just bring the two rc files up in VC and drag and drag the dialog resources across. Ditto for the string and avi resources.
3. To add a library to be linked with your code, just use Project -> Settings -> Link Tab -> General Category and add wininet.lib to the object / libraries modules edit box. To add multiple entries just leave a space between each one. This is VC 101 and I would suggest you consult books online for issues such as this as well as doing some of the sample apps provided in the VC tutorials.
|
|
|
|
|
Thanks for the reply.
I did finally get the HTML help and got it to work.
I winded up manually copying all of the resource stuff manually with a text editor.
I have VS .NET 2003 ... I brought up the sample program, as well as my test dummy program side by side. I tried repeatedly clicking on the resource and dragging it into the other program, but I just can't "automatically" get it to go. It "appears" that it is going to let me drop it, because the arrow turns into an arrow with a box around it, but it never shows up. I've tried "copy" and "paste" as well, but no go.
As for the library linking. In the passed three months, I have done over 200 examples and read tons of articles on this site (I've spent probably 8-10 hours every day here ). I've read several times, and everyone had something different to say about how to add external resources for linking. Some said what you mentioned, others say it goes as an additional dependency, while others said add it into command line arguments.
Before using this sample program, I did not ever read anywhere about adding it in as a dependency. I was trying to put it where I read in the command line argument, and error after error came up. When I brought the two projects up side by side, and went through every single option, I finally found the "right" place to put it.
I thank you for the reply. I did get everything going finally and it works great!
Shultas
|
|
|
|
|
Resources: All I can say is that in VC 6, drag and drop of resources works no problem. Seems to be another step backgrounds by MS in their development environments.
Linking: Just to let you know that I have updated the version on my web site so that you do not need to manually change your linker settings.
|
|
|
|
|
The Example Code works just fine but in my own Project the Compiler yields:
9 unresolved external symbols
for example: __imp__HttpSendRequestA@20
did i forget anything, or am I just too stupid to run VC++?
bye, Flo
|
|
|
|
|
Include wininet.lib in the import libraries for your app
|
|
|
|
|
|
Yeah, it works fine now, thnak you very much!
The specific directory where i found wininet.lib is included in the path for .lib-files, but wasnt found by the compiler. What tha heck...?
mfg Flo
|
|
|
|
|
Respected P J ,
How can I implements the same in ATL(without MFC support)
regards
Balkrishna Talele
|
|
|
|
|
Fire up your development environment and start writing code
|
|
|
|
|
is there anything special i need to do to make this work with binary downloads?
in testing, it looks like it only gets the first 20 bytes or so (16 bytes?) then it starts grabbing garbage.
(using the code from your website)
-c
ClickPic | ImgSource | CheeseWeasle
|
|
|
|
|
I have not heard of any reported problems in this area. A few things to try: Try a different web server to see if it is a server specific problem and make sure you have the latest version from my web site at www.naughter.com
|
|
|
|
|
When download is cancelled the dialog still shows Aborting and dose'nt abort
|
|
|
|
|
Make sure you get the latest version from my web site (www.naughter.com) as this class has gone thro quite a few updates since I posted this article to CodeProject.com
|
|
|
|
|
looking at source code of HTTP download Dialog app (void CHttpDownloadDlg::DownloadThread()) I see that you downloading files by chunks of 50 bites as in http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B149413
But there it is written "// Note: bigger buffer will greatly improve performance." Experimenting with these chunk size I found out that if I set big chumk size (e.g. 10mb), InternetReadFile can return with GetLastError "wrong parametr" if in reality file is small.
In other words, have you any suggestions about the best and safe chunk size in InternetReadFile?
Maybe 50 bytes is the safest one?
|
|
|
|
|
This is only when the http request needs to be resent because of authentication problems etc. Normally the code uses a 1024 byte buffer which I have had no reported problems with
|
|
|
|
|
Hi Mike,
How to make it support download resuming. Though the server supports download resuming, what necessary change has to be made in the client to handle it. Kindly help me. Thank you.
Sundar
|
|
|
|
|
The latest version on my web site (www.naughter.com) includes resume support
|
|
|
|
|
Hay,
It is excellant work.But there is still some modification for this.Suppose if you are downloading a large size file(nearly 68MB) the progressbar is not working properly.Can anybody have an idea.But really it is a great work.
Thank you.
|
|
|
|
|
First thing to do is make sure you have the latest version from my web site (www.naughter.com) as there have been a number of updates related to the progress bar
|
|
|
|
|
Same problem with v1.14 when downloading a file of 70 Mb
I think the problem is when the result of ((dwFileSize+512)/1024) is larger then a short integer
I've changed the following to fix this
void CHttpDownloadDlg::SetProgressRange(DWORD dwFileSize)
{
m_ctrlProgress.SetRange(0, (short)((dwFileSize+512)/1024));
}
to:
void CHttpDownloadDlg::SetProgressRange(DWORD dwFileSize)
{
m_ctrlProgress.SetRange32(0, (int)((dwFileSize+512)/1024));
}
Thanks PJ Naughter for sharing your code.
|
|
|
|