Results 1 to 5 of 5

Thread: Upload files bigger than available memory

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2010
    Posts
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    1

    Post Upload files bigger than available memory

    Can someone please explain to me how to upload files which are bigger than available memory?
    I looked at every example and they all load complete files with readAll() and then send them.
    This is not an option for me on S60 platform coz I hit Out-of-memory error.
    I tried to do it with QNetworkAccessManager:: post() method and I failed.
    Now, I'm trying to use QTcpSocket, but I don't know how to send and format the header before sending content??
    I attached a part of my code:
    Qt Code:
    1. tcpSocket = new QTcpSocket();
    2.  
    3. QString param = "upload.txt";
    4.  
    5. QNetworkAccessManager *http_upload = new QNetworkAccessManager(this);
    6. QNetworkRequest requpl;
    7.  
    8. QString toDropboxDir = metadata.value("path");
    9. if (!toDropboxDir.isEmpty())
    10. {
    11. toDropboxDir = toDropboxDir.right(toDropboxDir.size()-1);
    12. }
    13.  
    14. std::string stuff_std = OAuthWebRequestUpload("http://api-content.dropbox.com/0/files/dropbox/"+toDropboxDir.toStdString(),"POST",consumerKey,consumerSecret,token,secret,"",param.toStdString());
    15. QString stuff = QString::fromStdString(stuff_std);
    16. QByteArray stuff_BA;
    17. stuff_BA = stuff.toAscii();
    18.  
    19. qsrand(QDateTime::currentDateTime().toTime_t());
    20. QString boundary_random = QVariant(qrand()).toString()+QVariant(qrand()).toString()+QVariant(qrand()).toString();
    21. QString crlf("\r\n");
    22. QString boundaryStr("---------------------------"+boundary_random);
    23. QString boundary="--"+boundaryStr+crlf;
    24.  
    25. tcpSocket->connectToHost("api-content.dropbox.com",80);
    26. connect(tcpSocket, SIGNAL(connected()), this, SLOT(filler()));
    27. connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(erase_multipartform()));
    28.  
    29. //setting header to the request (with neccessary OAuth authorization)
    30. requpl.setUrl(QUrl(QString("http://api-content.dropbox.com/0/files/dropbox/"+metadata.value("path"))+"?file="+param));
    31. requpl.setRawHeader("Authorization", stuff_BA);
    32. requpl.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary="+boundaryStr);
    33. QFile *file_upload = new QFile(param_path);
    34. file_upload->open(QIODevice::ReadOnly);
    35.  
    36. //sending content
    37. QByteArray payload;
    38. QDataStream stream(&payload, QIODevice::WriteOnly);
    39. stream.setVersion(QDataStream::Qt_4_7);
    40. stream << "Authorization "+stuff;
    41. qDebug() << "Authorization "+stuff;
    42. stream << "--"+boundaryStr << "\r\n";
    43. //qDebug() << "--"+boundaryStr << "\r\n";
    44. stream << "Content-Disposition: form-data; name=\"file\"; filename=\""+param+"\"" << "\r\n";
    45. //qDebug() << "Content-Disposition: form-data; name=\"file\"; filename=\""+param+"\"" << "\r\n";
    46. stream << "Content-Type: text/plain" << "\r\n" << "\r\n";
    47. //qDebug() << "Content-Type: "+param_mime << "\r\n" << "\r\n";
    48.  
    49. int iBlock = 0;
    50. while(!file_upload->atEnd())
    51. {
    52. qDebug()<<"Reading Line: "<<++iBlock;
    53. //stream << (quint16)0;
    54. //stream << file_upload->readLine().data();
    55. stream << file_upload->readAll().data();
    56. tcpSocket->write(payload);
    57. tcpSocket->flush();
    58. //qDebug() << QString(file_upload->readAll().constData());
    59. payload.clear();
    60.  
    61. }
    62. file_upload->close();
    63. stream << "\r\n" << "--"+boundaryStr+"--" << "\r\n";
    64. //qDebug() << "\r\n" << "--"+boundaryStr+"--" << "\r\n";
    65. reply_upload = http_upload->post(requpl,payload);
    66. connect(reply_upload, SIGNAL(finished()), this, SLOT(readData_upload()));
    To copy to clipboard, switch view to plain text mode 

    Please help me, I'm stuck on this for days now...
    Last edited by knobtviker; 19th December 2010 at 13:39.

Similar Threads

  1. Selected row bigger than others in QTableView
    By JuanMO in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2010, 17:48
  2. Do resources in QRC files consume memory?
    By TheNewGuy in forum Newbie
    Replies: 1
    Last Post: 7th December 2009, 09:07
  3. upload movie files to youtube
    By jay in forum Qt Programming
    Replies: 0
    Last Post: 21st September 2009, 13:34
  4. upload files using QNetworkAccessManager
    By Raajesh in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2008, 20:43
  5. Replies: 2
    Last Post: 23rd November 2007, 18:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.