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
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();
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();
You can create your own data structure that will represent file contents and its file name and convert it to QByteArray and vice versa.
You can send two requests: the first with the file name and the second with data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With