Is there any simple way to send a file to server with the filename included so that the filename in server and client are exactly the same?
Here is my code
Sender
QString path = QApplication::applicationDirPath()+"/belajardansa.bmp";
QFile inputFile(path);
QByteArray read ;
inputFile.open(QIODevice::ReadOnly);
while(1)
{
read.clear();
read = inputFile.read(32768*8);
qDebug() << "Read : " << read.size();
if(read.size()==0)
break;
qDebug() << "Written : " << socket->write(read);
socket->waitForBytesWritten();
read.clear();
}
inputFile.close();
Receiver
QTcpSocket* socket = static_cast<QTcpSocket*>(sender());
QBuffer* buffer = buffers.value(socket);
QByteArray read = socket->read(socket->bytesAvailable());
qDebug() << "Read : " << read.size();
QFile file( ???); // what should I put in the bracket???
if(!(file.open(QIODevice::Append)))
{
qDebug("File cannot be opened.");
exit(0);
}
file.write(read);
file.close();