Help!!Get image and save at local computer...
-
Here is the code the get image and save as the computer!!!However, sometimes the image did not get all bytes. (e.g image size= 85,687 bytes but it only get 75,776 bytes) It is sometimes only.....I don't know what the problem is? Can anyone help?
UINT nBytesRead; TCHAR szBuf[CHUNK_SIZE] = {0}; CFile objThumbFile; CHttpFile* pHttpFile = pHttpConnection->OpenRequest (_T("GET"), _T(strPhotoLink), NULL, 1, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD); CString strResponse; if(!objThumbFile.Open(strOutputFileName, CFile::modeCreate | CFile::modeWrite, NULL)) return false; // 7. Read the response text do { nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE); strResponse += szBuf; objThumbFile.Write(szBuf, CHUNK_SIZE); //if(nBytesRead < CHUNK_SIZE) //break; i++; //}while(nBytesRead == CHUNK_SIZE); }while(nBytesRead > 0); objThumbFile.Close();
-
Here is the code the get image and save as the computer!!!However, sometimes the image did not get all bytes. (e.g image size= 85,687 bytes but it only get 75,776 bytes) It is sometimes only.....I don't know what the problem is? Can anyone help?
UINT nBytesRead; TCHAR szBuf[CHUNK_SIZE] = {0}; CFile objThumbFile; CHttpFile* pHttpFile = pHttpConnection->OpenRequest (_T("GET"), _T(strPhotoLink), NULL, 1, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD); CString strResponse; if(!objThumbFile.Open(strOutputFileName, CFile::modeCreate | CFile::modeWrite, NULL)) return false; // 7. Read the response text do { nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE); strResponse += szBuf; objThumbFile.Write(szBuf, CHUNK_SIZE); //if(nBytesRead < CHUNK_SIZE) //break; i++; //}while(nBytesRead == CHUNK_SIZE); }while(nBytesRead > 0); objThumbFile.Close();
You can use also from
URLDownloadToFile
_**
**_
WhiteSky
-
Here is the code the get image and save as the computer!!!However, sometimes the image did not get all bytes. (e.g image size= 85,687 bytes but it only get 75,776 bytes) It is sometimes only.....I don't know what the problem is? Can anyone help?
UINT nBytesRead; TCHAR szBuf[CHUNK_SIZE] = {0}; CFile objThumbFile; CHttpFile* pHttpFile = pHttpConnection->OpenRequest (_T("GET"), _T(strPhotoLink), NULL, 1, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_EXISTING_CONNECT | INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_RELOAD); CString strResponse; if(!objThumbFile.Open(strOutputFileName, CFile::modeCreate | CFile::modeWrite, NULL)) return false; // 7. Read the response text do { nBytesRead = pHttpFile->Read((void*) szBuf, CHUNK_SIZE); strResponse += szBuf; objThumbFile.Write(szBuf, CHUNK_SIZE); //if(nBytesRead < CHUNK_SIZE) //break; i++; //}while(nBytesRead == CHUNK_SIZE); }while(nBytesRead > 0); objThumbFile.Close();
mimimimilaw wrote:
strResponse += szBuf;
If
szBuf
contains more than one\0
character, this obviously will not work.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb