Transfer Image to Server in C++

hi friends..
I want to sent an image from client to server in c++ on windows plate form.
can any one tell me how to read an image and convert it into byte array? And on server side how to create the image again from the received data?
Is sending byte array is same as sending characters??

I m very thankful for your kind help.
Use sockets to do the sending and receiving. Open your files in binary mode.
I do that but not working. Actually i save the image data in buffer but when i send it to server it does not do any thing. image file is created but "no preview is available" error is shown.
What error are you seeing? Run cksum on the file before you transmit it and again when you receive it. Are they the same?
[b]No. when i receive the data on server side it is not same as i send from client...

This is the Code which i am trying to use. but not working.


Client Side code[/b]

long len;
char* buf = NULL;
FILE* fp = NULL;
fp = fopen( "image.jpg", "rb" );
if (fseek( fp, 0, SEEK_END ) != 0)
{
fclose( fp );
}
len = ftell( fp );
rewind( fp );
buf = (char*)malloc( len );
if (!buf)
{
fclose( fp );
}
if (!fread(buf,len,1,fp))
{
fclose( fp );
}
fclose( fp );
//******************
if( (bytecount=send(hsock, buf, strlen(buf),0))==SOCKET_ERROR){
fprintf(stderr, "Error sending data %d\n", WSAGetLastError());
goto FINISH;
}
printf("Sent bytes %d\n", len);

Sever Side Code:

int *csock = (int*)lp;

char buffer[102400];
long buffer_len = 102400;
long bytecount;

memset(buffer, 0, buffer_len);
if((bytecount = recv(*csock, buffer, buffer_len, 0))==SOCKET_ERROR){
fprintf(stderr, "Error receiving data %d\n", WSAGetLastError());
goto FINISH;
}
printf("Receive bytes %d\n", buffer_len);
//******************
FILE* fp = NULL;
fp = fopen( "image.jpg", "wb" );
if (!fwrite (buffer, 1, buffer_len, fp))
{
fclose( fp );
}
fclose( fp );
//**********
Thanks Bros. I got the solution. Thanks alot for your kind help
Topic archived. No new replies allowed.