Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook



The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic

Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.

If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.

Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.

Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

String to varbinary blob

  • Filter
  • Time
  • Show
Clear All
new posts

    String to varbinary blob

    I have a non-Phonegap application, am storing user input in localstorage when there's no web connection. It's worked well for a couple of years, just a text string in XML format.

    Now I need to add an image (.jpg) to that offline storage and then retrieval and insert to MS SQL.

    Along with this, I do have an an immediate submit for those occasions when there is a connection. The photo, the photo_thumb and everything else get inserted to SQL just fine. So my basic setup is sound. In the data-bound functionality, I just bind the Image type control to the Photo (B) field, and all is well.

    While I can store, retrieve, and insert the image from the localstorage string, I'm not getting the right data format for the image into the varbinary field.


    vPhoto = extract_string(rowdata, "<_PHOTO>", "</_PHOTO>")
    vblob = char_to_blob(vPhoto)
    args.set("Photo", vblob)
    is inserting data to the varbinary field, but it's not quite right to be retrieved as an image.

    I've tried everything I can think of:

    vblob = base64decode(vblob)
    vblob = base64decode(substr(vblob,23))
    as well as simply inserting the vPhoto string from localstorage.

    Nothing is storing/producing the right data to correctly store the image.

    Anyone have the magic keys?

    Re: String to varbinary blob

    Bumping this up. Surely there's way to do this:

    1. Store the mobile device's picture (jpg image) to local storage along with other data in the XML string.

    2. Include the image in the string when picked up in a callback

    3. Convert the string (I presume) for proper image storage in the MS SQL varbinary field.



      Re: String to varbinary blob

      It seems that I'm so close to a solution, I think it's worth the details of what I'm doing.

      To add the image data to the XML string put in localstorage, I'm doing this:

      	var vele = document.getElementById('{dialog.componentname}.V.R1.PHOTO').src;
      	var params = '<_PHOTO>' + vele + '</_PHOTO>'
      	txt = txt.concat(params);
      This appears to work well, presents data in the XML string with a bit of a header as I'd expect:

      data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gx. . .
      So, when I retrieve it with a callback:

      		dim vblob as b
      		vblob = char_to_blob(extract_string(rowdata, "<_PHOTO>", "</_PHOTO>"))
      		vblob = base64decode(substr(vblob,23))
      		args.set("Photo", vblob)
      this produces a value in the SQL Photo field that appears to be very consistent with the values of images recorded through the regular data binding.

      Yet, the UX image field control doesn't display this as a photo - just shows a broken image icon.

      I'm missing some detail, but sure don't know what that might be.



        Re: String to varbinary blob

        your code is wrong. you are not stripping off the data uri prefix correctly.

        you have substr(vblob,23)

        but if the data is as shown below, you can see that 23 is the wrong value.

        txt = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/4gx"
        = ",/9j/4AAQSkZJRgABAQEASABIAAD/4gx"

        you need to use 24

        = "/9j/4AAQSkZJRgABAQEASABIAAD/4gx"


          Re: String to varbinary blob

          Despite Selwyn's help, verifying that I seem to be doing things correctly, this still doesn't work. I cannot seem to store the character string that comprises the image in the XML, saved to local storage, then get it back out and create a usable image.

          So in trying to make this work, I have this oddity:

          Executive summary: If I copy/paste the string from the localstorage value into a text file, and allow the Callback to process that, I get an image. If I process the string within the callback - whether saved to file or just as a variable, I do not get a result that produces a useful image.

          To find this out:

          I copied/pasted the image string from the value in localstorage, and put it into PHOTO1.TXT.

          Then, I let the Xbasic process the XML string and stored the result of this value in PHOTO2.TXT, with this:

          		photo = extract_string(rowdata, "<_PHOTO>", "</_PHOTO>")
          		save_to_file(photo, "c:\temp\photo2.txt")
          A visual comparison shows that at least the beginning and ending characters are the same.

          I've picked them up with file.to_string() and compared their lengths - perfect match.

          But, comparing the strings shows me they do not match. The below says they are not equal:

          ' Copy/pasted from localstorage console:
          photo1 = file.to_string("C:\Temp\Photo1.txt")
          photo1 = word(photo,2,",")
          ' generated from callback:
          Photo2 = file.to_string("C:\Temp\Photo2.txt") 
          photo2 = word(photo2,2,",")
          result = "false"
          if Photo1 = Photo2
          	result = "true"
          end if
          So, how is it that the string I get from copy/paste of the localstorage value is different from that string I get by pulling it out of some XML with extract_string(rowdata, "<_PHOTO>", "</_PHOTO>") ? And, again, beginning and ending values appear identical, lengths match exactly, but something else is different and I don't know what.


            Re: String to varbinary blob

            i don't see how you can expect to get an answer without including a test case.

            i have already sent you a test case of my own which works. so once we get your test case we can compare it with the working test case.