C++, Ifstream opens local file but not file on HTTP Server
- by fammi
Hi,
I am using ifstream to open a file and then read from it.
My program works fine when i give location of the local file
on my system.
for eg
/root/Desktop/abc.xxx works fine
But once the location is on the http server the file fails to
open.
for eg
http://192.168.0.10/abc.xxx fails to open.
Is there any alternate for ifstream when using a URL address?
thanks.
part of the code where having problem:
bool readTillEof = (endIndex == -1) ? true : false;
// Open the file in binary mode and seek to the end to determine file size
ifstream file ( fileName.c_str ( ), ios::in|ios::ate|ios::binary );
if ( file.is_open ( ) )
{
long size = (long) file.tellg ( );
long numBytesRead;
if ( readTillEof )
{
numBytesRead = size - startIndex;
}
else
{
numBytesRead = endIndex - startIndex + 1;
}
// Allocate a new buffer ptr to read in the file data
BufferSptr buf (new Buffer ( numBytesRead ) );
mpStreamingClientEngine->SetResponseBuffer ( nextRequest,
buf );
// Seek to the start index of the byte range
// and read the data
file.seekg ( startIndex, ios::beg );
file.read ( (char *)buf->GetData(), numBytesRead );
// Pass on the data to the SCE
// and signal completion of request
mpStreamingClientEngine->HandleDataReceived( nextRequest,
numBytesRead);
mpStreamingClientEngine->MarkRequestCompleted( nextRequest );
// Close the file
file.close ( );
}
else
{
// Report error to the Streaming Client Engine
// as unable to open file
AHS_ERROR ( ConnectionManager,
" Error while opening file \"%s\"\n",
fileName.c_str ( ) );
mpStreamingClientEngine->HandleRequestFailed( nextRequest,
CONNECTION_FAILED );
}
}