NetTalk Central

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jslarve

Pages: [1] 2
1
Web Server - Ask For Help / Re: Drag & Drop file upload
« on: July 11, 2020, 08:49:59 PM »
Thanks a whole lot Bill.  I appreciate it.

Hi,

I've done drag and drop within NetTalk for reordering uploaded photos. I know thats not the same but the drag and drop that is supported within html is "usable".

A html element say DIV can have a "draggable" attribute, so the browser knows it can be dragged.

Then you also have events for "ondrop" and "ondragover". Its all done client side in javascript. Untill you know what you want tell the server to do, then I can do an ajax call to tell NetTalk what needs to change in my database and if necessary refresh the div/divs.

I do have trouble with NetTalk 10 and multiple upload drop "destinations" on a popup window, not sure if thats me, NT10 and whether NT11 may have the same issue.

Its totally do-able, but it will take some work.

I've attached a picture and some of the html to give you a clue.

   <td>
      <div id="draggable_001" class="movable_img" ondrop="drop(event,1)" ondragover="allowDrop(event)">
         <a href="https://titan.inhabit.com.au/images/65/0003114436.JPG?s=0" target="_blank">
            <img draggable="true" ondragstart="drag(event,1)" src="https://titan.inhabit.com.au/thumbs/65/0003114436.JPG?s=0" width="100" alt="" border="0">
         </a>
      </div>
   </td>
   <td>
      <div id="draggable_002" class="movable_img" ondrop="drop(event,2)" ondragover="allowDrop(event)">
         <a href="https://titan.inhabit.com.au/images/65/0003114448.JPG?s=0" target="_blank">
            <img draggable="true" ondragstart="drag(event,2)" src="https://titan.inhabit.com.au/thumbs/65/0003114448.JPG?s=0" width="100" alt="" border="0">
         </a>
      </div>
   </td>
   <td>
      <div id="draggable_003" class="movable_img" ondrop="drop(event,3)" ondragover="allowDrop(event)">
         <a href="https://titan.inhabit.com.au/images/65/0003114446.JPG?s=0" target="_blank">
            <img draggable="true" ondragstart="drag(event,3)" src="https://titan.inhabit.com.au/thumbs/65/0003114446.JPG?s=0" width="100" alt="" border="0">
         </a>
      </div>
   </td>
   <td>
      <div id="draggable_004" class="movable_img" ondrop="drop(event,4)" ondragover="allowDrop(event)">
         <a href="https://titan.inhabit.com.au/images/65/0003114449.JPG?s=0" target="_blank">
            <img draggable="true" ondragstart="drag(event,4)" src="https://titan.inhabit.com.au/thumbs/65/0003114449.JPG?s=0" width="100" alt="" border="0">
         </a>
      </div>
   </td>
   <td>
      <div id="draggable_bin" ondrop="drop(event,-1)" ondragover="allowDrop(event)">
         <img draggable="false" src="https://titan.inhabit.com.au/_ui/rsc/trash-can.png" width="100" height="75" alt="" border="0">
      </div>
   </td>


<script>
function drop(e,idx) {
  e.preventDefault();
  var data=e.dataTransfer.getData("Text");
  if (data=="killfp1") {
    sv('','listingtable_listingtablew','','_refresh_=current','killfp1=65,'+idx+',519386','_parentproc_=listingtablew');
  } else if (data=="killfp2") {
    sv('','listingtable_listingtablew','','_refresh_=current','killfp2=65,'+idx+',519386','_parentproc_=listingtablew');
  } else if (idx==-1) {
    sv('','listingtable_listingtablew','','_refresh_=current','delete='+data+',519386','_parentproc_=listingtablew');
  } else {
    sv('','listingtable_listingtablew','','_refresh_=current','move='+data+','+idx+',519386','_parentproc_=listingtablew');
  }
}

function drag(e,idx) {
  e.dataTransfer.setData("Text",idx);
}

function allowDrop(e) {
  e.preventDefault();
}

function handleDragEnter(e) {
  this.className = 'over';
  return false;
}

function handleDragLeave(e) {
  this.className = '';
  return false;
}
</script>


Regards
Bill

2
Web Server - Ask For Help / Drag & Drop file upload
« on: July 10, 2020, 01:08:44 PM »
If anyone has an idea, I'd appreciate it.

I am interested in creating a web page with a fixed sized grid. Such as 2x4, 4x4, and 8x4.

The user would need to be able to drag a file (or multiple files) to a particular square in the grid (or multiple squares if multiple files).

Dragging a file into a square would initiate file upload. The user would also need to be able to move the file to a different square afterward.

Is there an example I could make use of, or perhaps a commercial script library that can be of use for this?

Thank you.

3
Web Server - Ask For Help / Re: Twilio Webhook for Receiving SMS?
« on: May 23, 2020, 07:38:45 AM »
Hi Bruce -

Sounds interesting. Does sms.capesoft.com also use Twilio or does it do the SMS stuff internally?

I would be interested in a beta account if you wouldn't mind. By "beta", does that mean you intend to make this a commercial product out of it some day?

Thank you.

Hi Jeff,

yeah, I did it for sms.capesoft.com
It's not terribly exciting - Twilio calls your web hook, which is jsut a NetWebServieMethod, and you can then process that like any other method.

I went a step further - the sms.capesoft.com server then has WebSockets connections from the clients. So if a client program sends an SMS, and that SMS gets a reply, then it's automatically pushed back into the client program, in real-time, even if the client program is behind a firewall.

If you're not too worried about doing it yourself, I can hook you up with a beta account on sms.capesoft.com to play with.

cheers
Bruce

4
Web Server - Ask For Help / Re: Twilio Webhook for Receiving SMS?
« on: May 22, 2020, 11:16:00 PM »
Thanks Bill.

Who are you using for SMS and do you like them? :)

I'm not married to Twilio. Haven't created an account yet.

Thanks again.

5
Web Server - Ask For Help / Twilio Webhook for Receiving SMS?
« on: May 22, 2020, 08:01:58 PM »
I'm interested in receiving SMS messages from Twilio.

Wondering if anyone has done this in NetTalk. There's this CSharp example. Looks pretty straightforward, but if anyone has already done this, I'd love to hear whatever advice you might have. https://www.twilio.com/docs/sms/tutorials/how-to-receive-and-reply-csharp

My intent is to display a QR code that I generate, which initiates an SMS message that gets sent to my Twilio number that my web app then receives.

Thank you.

6
Hi Bruce -

I am generating the images on the fly.

But saving to disk will probably work out best, with the "$$$" as Jane suggested.

Haven't had a chance to test it out yet, but will hopefully get some time next week.

Thank you.

Where did the stringtheory object come from?
Are you drawing something on the fly?
From a blob?

7
A StringTheory object.

I'll play with the $$$ file idea. Maybe that will be good enough. Thanks Bruce.

so, if it's not on disk, where is it?

cheers
Bruce

8
I was trying to avoid writing any files to disk. I'm already doing that in the returned XML/JSON. But I just wanted to serve the image. Thanks anyway.

Hi Jeff,

I think you are over-thinking this a bit :)

>> Maybe my question is too simple.
>> I'm asking what _I_ should on my NetTalk server do so that it's possible that THEY can do the simple GET to retrieve the image. :-)

The short answer is "nothing for you to do - it already does that".
The long answer adds the sentence ".. as long as the image is in the web folder,or sub folder.".

In other words, files in the web (or sub) folders can be served if the user just enters the name.
There's nothing for you do to - the server is a server, and this is what it serves.

There's no "API" involved here - serving files  is what the web server _does_.

I think you've gone down a very (very) common thought problem though. Typically we start with serving static files, then graduate to Web API's then Web Apps (then Mobile apps). Along the way we can start overthinking a situation - especially (I've noticed) serving static files.

_Of course_ it can then more complicated (like serving from a BLOB field etc), but at it's root static files in the web folder are just "served".

cheers
Bruce

9
Hi Jane -

Interesting. Maybe that would work for me. Thank you.

I'd still like to know if it would be possible to do it the other way, but the $$$ might do.

I appreciate your help.

Jeff,

Would it be unacceptable to create your image, save the result to a temporary file on the web server, and then serve that file?

If you begin the filename with $$$ then the file will be deleted from the server after it has been served once.  That's also the typical approach for creating and serving PDF reports.  (Search for "$$$" on this page: https://www.capesoft.com/docs/NetTalk11/NetWebReports.htm)


Jane

10
Hi Bruce -

Maybe my question is too simple.

I'm asking what _I_ should on my NetTalk server do so that it's possible that THEY can do the simple GET to retrieve the image. :-)

I want my own server to return the image (or other kinds of binary files), but I am looking for advice on how to accomplish that with NetTalk. I am currently returning JSON or XML, but I want to know the NetTalk way to to return a non-static image (that I generate) without encoding it into JSON or XML.

Does that make any sense?

Thank you.

>> say, I wanted to have the quickest route to providing an image src=https://MyApi.com?YadaYada

they they should simply use a URL.
src="https://myapi.com/whatever.jpg"
Assuming that whatever.jpg is in the web folder.
or say
src="https://myapi.com/images/whatever.jpg"
if it is in the \web\images folder.

>> In cases where I am able to do a GET, it would be cool if I could just return the image (not in XML or JSON) for direct use on the page.

same URL - just do a simple GET.

Cheers
Bruce

11
>> So really all you need to do is jsonDecode it before sending it to your text control.

Okay. Thank you.

>> to whom? A browser? An API Client?
Generally speaking base64 is the best way to send data back, but context is everything.

If, say, I wanted to have the quickest route to providing an image src=https://MyApi.com?YadaYada on a web page.
But since I need to send an image too, I guess that's not so simple to do when I need to POST.
In cases where I am able to do a GET, it would be cool if I could just return the image (not in XML or JSON) for direct use on the page.

>>>> Wondering if the stuff inside the "<DecodedImage>" tag could be the result itself.
>>not if the result is returned as XML or JSON since neither of those are binary formats. In both those cases base64 of teh binary is the best option.

Was wondering if I could have the option of JUST returning the image. Not inside XML or JSON. I am still pretty noob with NetTalk.

I'm talking about something like they're talking about on this page. https://stackoverflow.com/questions/39177576/how-to-to-return-an-image-with-web-api-get-method

Thanks for getting back to me Bruce.

Hi Jeff,

>> Apparently json doesn't support multi-line data very well,

it supports it perfectly. But JSON encoding requires <13> to be encoded as \r and <10> as \l.
So really all you need to do is jsonDecode it before sending it to your text control.

>> I guess my real question is: What is the best way to serve up an image?

to whom? A browser? An API Client?
Generally speaking base64 is the best way to send data back, but context is everything.

>> Wondering if the stuff inside the "<DecodedImage>" tag could be the result itself.
not if the result is returned as XML or JSON since neither of those are binary formats. In both those cases base64 of teh binary is the best option.

cheers
Bruce

12
This doesn't guarantee that a PNG file is 100% valid, but it gives a few sanity checks before attempting to save and process the file as PNG.

Makes sure that there's a valid PNG header and checks the dimensions to make sure they're in range of your specifications.

This way, the image never needs to hit the disk if it doesn't pass the vetting.

Usage:

MyImageST    StringTheory
MyMessageST StringTheory

   CODE

  !Assuming MyImageST already contains the PNG data

    IF NOT ValidatePNGFile(MyImageST,MyMessageST)
        !Don't bother saving/processing
        MESSAGE('Invalid Image: ' & MyMessageST.GetValue())
    END

ValidatePNGFile      PROCEDURE  (StringTheory pPngContentsST,StringTheory pResultMsgST,|
                            LONG pMinWidth=10,LONG pMaxWidth=1200,LONG pMinHeight=10,LONG pMaxHeight=1200)!,LONG
S                           STRING(4) !4 bytes to be examined as LONG using L.
L                           LONG,OVER(S)
IHDRPos                     LONG !Position of the IHDR chunk
ST                          StringTheory !Utility StringTheory object.

  CODE

    LOOP 1 TIMES     
        pResultMsgST.SetValue('')
        IF pPngContentsST.Slice(1,8) <> '<089h,050h,04Eh,047h,00Dh,00Ah,01Ah,00Ah>'
            pResultMsgST.SetValue('Invalid PNG file')
            BREAK
        END
        IHDRPos = pPngContentsST.Instring('IHDR')
        IF NOT IHDRPos
            pResultMsgST.SetValue('Cannot Determine PNG Dimensions')
            BREAK
        END
       
        S = pPngContentsST.Slice(IHDRPos + 4,IHDRPos + 8 ) !Getting The Width (but it's BigEndian)
        L = ST.SwitchEndian(L)                            !Switch to LittleEndian so we can read it.
        IF L < pMinWidth OR L > pMaxWidth
            pResultMsgST.SetValue('Width is out of Bounds: Value=' & L & ' Minimum=' & pMinWidth & ' Maximum=' & pMaxWidth)
            BREAK
        END
       
        S = pPngContentsST.Slice(IHDRPos + 8,IHDRPos + 12) !Getting The Height (but it's BigEndian)
        L = ST.SwitchEndian(L)                             !Switch to LittleEndian so we can read it.
        IF L < pMinHeight OR L > pMaxHeight
            pResultMsgST.SetValue('Height is out of Bounds: Value=' & L & ' Minimum=' & pMinHeight & ' Maximum=' & pMaxHeight)
            BREAK
        END
        RETURN 1
    END
    RETURN 0

13
Hi Jane -

Thanks for your help. I think it works okay without me messing with that. Apparently json doesn't support multi-line data very well, so it's probably best to serve it as one big string.

I guess my real question is: What is the best way to serve up an image?

Instead of XML or JSON, is it possible to simply return an image or other binary file?

either as:

 'data:image/png;base64,' & MyBase64EncodedPngImageStringTheory.GetValue()

 or:

 MyBinaryDataStringTheory.GetValue()

I attached the current XML result.

Wondering if the stuff inside the "<DecodedImage>" tag could be the result itself.

Thank you.


14
Hi Jane -

My StringTheory object does the Base64Encode() using the default parameters inside the ServiceMethod ROUTINE (which splits it up into 75 character lines).

The StringTheory object is set as a return.

With XML, it leaves the contents split up.

With JSON, it strips out the CRLF. 

Now that I know that the horizontal scroll helps, it's not that big of a deal. Just trying to understand if that's intentional.

I'm wondering if I should prepend the image with "data:image/png;base64," or if I'd be better off with plain ol' bas64 or if there's a better method of delivery.

Thanks for your response.



Speaking from pure guesswork and no knowledge, Jeff.

But I'm wondering how you're converting it in your API server prior to sending it back.

Have you tried using a String Theory object and playing with the st:nowrap property? 
https://www.capesoft.com/docs/StringTheory3/StringTheory.htm#stBase64Encode

It would appear that its default is to do the wrapping.  Which is apparently the RFC default.

Can you use debug code in your service and see what's being done differently between the XML and JSON outputs?

Yours in ignorance,

Jane

15
Adding a HScroll to my textbox helped with this, but I'm still interested in hearing whether the b64 can be split and still work.

Thanks

I have an API server where you upload an image and it returns a processed image encoded with B64.

It works fine when using SetAccept('xml') on the client. Pretty snappy. The b64 is split up into 75 character lines. Groovy.

When SetAccept('json'), it works fine, but the b64 is returned as one large string (not multi lined).

This makes it impossible for a TEXT control to view it. It just freezes up. I guess that's OK if I can't load in a TEXT control, but I'd like to be able to if possible.

2 Questions:

  • Is using b64 the wrong approach for returning an image? I want to avoid saving the image on disk.
  • Is there a setting to allow the B64 to be split up in the json version?
Thanks.

Pages: [1] 2