Results 1 to 20 of 22

Thread: Prob with store and retrieve binary data to/from remote sqlserver's image field

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Posts
    54
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Sorry Mr.Wysota
    Its my mistake, i should post my thread with clear codes and explanations. sorry once again.

    the retrieved value from xml file is in binary base64 encoded, so i created another one byte array (byte) to store the base64 decoded binary data, for that i used the following syntax...

    Qt Code:
    1. QByteArray byte(QByteArray::fromBase64(wBData1));
    To copy to clipboard, switch view to plain text mode 

    then im storing the contents of the variable byto into a already opened file, code given below

    Qt Code:
    1. fil.write(byte);
    2. fil.close();
    To copy to clipboard, switch view to plain text mode 

    fil is file object already opened,

    after doing all these things i could not get the original file (for eg image) what im stored before into the server.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    How does your xml parser look like? If the code you pasted is complete, it means that you don't have a parser and you "forgot" to read QXmlStreamReader documentation which you should now do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2009
    Posts
    54
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    sorry
    i didnt pasted here the code for xml parsing .
    now i gave the complete code for retrieving data from remote sql server & parsing the retrieved xml file.

    Qt Code:
    1. QNetworkReply *reply;
    2. QFile fil("testsnd");
    3. if(!fil.open(QIODevice::WriteOnly))
    4. {
    5. qDebug() << "cannot open file for writing"<<qPrintable(fil.errorString()) <<endl;
    6. return 0;
    7. }
    8. reply=net.get("http://192.168.0.220/clancor?sql=select+photo+from+blob+where+sno+=+4+F OR+XML+RAW,+BINARY+BASE64&root=blobinsert&contentt ype=text/xml")
    9. connect(reply, SIGNAL(finished()),&loop,SLOT(quit()));
    10. loop.exec(); //entering event loop until reply object's finished() signal gets activated
    11.  
    12. QXmlStreamReader xml(reply->readAll()); //storing retrieved xml file content xmlstreamreader object
    13. while (!xml.atEnd())
    14. {
    15. xml.readNext();
    16. if (xml.tokenType() == QXmlStreamReader::StartElement)
    17.  
    18. if (xml.name() == "row")
    19. {
    20. wBData1.append(xml.attributes().value("photo").toString());
    21. }
    22. }
    23. QByteArray byte(QByteArray::fromBase64(wBData1));
    24. fil.write(byte);
    25. fil.close();
    To copy to clipboard, switch view to plain text mode 
    Last edited by Askar; 30th September 2009 at 14:54.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Quote Originally Posted by Askar View Post
    now i gave the complete code for retrieving data from remote sql server & parsing the retrieved xml file.
    You could have done that 12 posts ago...

    Are you sure "photo" is an attribute and not an element?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2009
    Posts
    54
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    ya sure............

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    What does this return?
    Qt Code:
    1. qDebug("%d", wBData1.size());
    2. qDebug("%d", byte.size());
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2009
    Posts
    54
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    wBData1.size() returns-----------12
    byte.size() returns------------------7

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Somehow I doubt you can fit an image with all its headers in 7 bytes...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Sep 2009
    Posts
    54
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    dear Wysota,

    while inserting binary value into the remote server database table with the following code

    Qt Code:
    1. QString str;
    2. QFile fileIn ("Sunset.jpg");
    3. QByteArray wBData;
    4. net = new QNetworkAccessManager();
    5. if (fileIn.open (QIODevice::ReadOnly))
    6. {
    7. wBData.append(fileIn.readAll());
    8.  
    9. }
    10. qDebug()<<wBData.size(); //returns 59129
    11. str.append(wBData)
    12. net.get("http://192.168.0.220/clancor?sql=insert+into+blob+(sno,photo)+values+(4 ,'"+ str +"')&root=blobinsert"
    To copy to clipboard, switch view to plain text mode 

    qDebug returns value 59129

    but while retrieving same binary data value from remote server qdebug returns

    wBData1.size() returns-----------12
    byte.size() returns------------------7

    which is entered in the previous thread

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    What's the whole xml you get from the server? Also how do you know the image is stored correctly? You are not encoding the data here anywhere...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Sep 2009
    Posts
    54
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Dear Wysota;
    yes im not encoding the data while storing, but im storing the contents of byte array contents into a QString object while inserting the binary value into the remote server ( the code i gave in previous thread).

    the whole xml contents which im retrieving are given below,
    Qt Code:
    1. <?xml version="1.0" encoding="utf-8" ?><blobinsert><row photo="w7/DmMO/w6A="/></blobinsert>
    To copy to clipboard, switch view to plain text mode 


    from the xml file i retrieved from the server the base64 encoded binary contents are
    w7/DmMO/w6A=

    Please let me know, where im getting wrong ? and what is the correct way to do this process

    Thanks,

  12. #12
    Join Date
    Sep 2009
    Posts
    54
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 3 Times in 3 Posts

    Default Re: Prob with store and retrieve binary data to/from remote sqlserver's image field

    Dear Wysota;
    yes im not encoding the data while storing, but im storing the contents of byte array contents into a QString object while inserting the binary value into the remote server ( the code i gave in previous thread).

    the whole xml contents which im retrieving are given below,


    Qt Code:
    1. <?xml version="1.0" encoding="utf-8" ?><blobinsert><row photo="w7/DmMO/w6A="/></blobinsert>
    To copy to clipboard, switch view to plain text mode 


    from the xml file i retrieved from the server the base64 encoded binary contents are
    w7/DmMO/w6A=

    Please let me know, where im getting wrong ? and what is the correct way to do this process

    Thanks,

Similar Threads

  1. Replies: 0
    Last Post: 19th September 2009, 07:07
  2. Replies: 0
    Last Post: 14th September 2009, 11:57
  3. Replies: 2
    Last Post: 14th September 2009, 08:31

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.