Web Connection
Web Connection 6.20 and 16mb Uploads - Client and Server
Gravatar is a globally recognized avatar based on your email address. Web Connection 6.20 and 16mb Uploads - Client and Server
  Rick Strahl
  All
  Apr 18, 2018 @ 06:29pm

Hi all,

Web Connection 6.20 is out and there's a new feature that was snuck in that now allows the wwHttp Class to upload files larger than 16mb to a server from your FoxPro applications.

As you probably know FoxPro has a 16mb string size limit for strings. It turns out there are a few loopholes in that 'rule' and accordingly there are some workarounds to make this work.

In a nutshell you can use larger than 16mb strings in FoxPro as long as you don't mutate the string in memory. You can assign a >16mb string, you can even use things like SUBSTR() and AT() on it, but you can't manipulate the string directly. In most cases you also can't concatenate two strings together to get a string >16mb.

Long story short, Keith Hackett last year provided the incentive for a work around to server side handling of >16mb file uploads in Web Connection. The fix for this was to capture the data as a single string and only re-assign it explicitly to a new variable rather than manipulating the string with many small concat and slice operations.

A few weeks back a request came in here on the message board for being able to upload files larger than 16mb with wwHttp and I revisited this problem in light of the server side solution and Web Connection 6.20 now has a solution for this.

What you can now do

You can now create a request where you know you're dealing with large post buffers like this:

DO wwHttp
loHttp = CREATEOBJECT("wwHttp")

loHttp.lUseLargePostBuffer = .T.       && Support >16mb
loHttp.nHttpPostMode = 2               && multi-part forms

loHttp.AddPostKey("title","Some Large Picture")
loHttp.AddPostKey("image","c:\temp\VeryLargeImage.tif")

loHttp.Send("https://somesite.com/uploadFiles")

The .lUseLargePostBuffer property is new and triggers wwHttp to use a file-buffered POST buffer. All form variable data that's normally added with .AddPostKey() is now added to a new wwFileStream instance. This class just takes string input and buffers it to file which can be of any size. When the post buffer is ready to be sent wwHttp now reads the buffered file (wwFileStream::ToString()) to a variable which - oddly enough is valid even if the string is massive (I used a 80meg file). The single variable can then be streamed to the server during the upload and it all works.

The takeaways here are this.

You can do

  • You can use >16mb strings in FoxPro
  • Load large string from file
  • Create large strings with wwFileStream
  • You can also do lcoutput = lcoutput + "xxx" to create large strings

You can't do

  • Concat two strings to get a string >16mb
  • Add a static string to a large string (lcOutput = lcOutput + ",")
  • Manipulate a large string with mutating functions like STRTRAN()

The rules about what works and what doesn't with large string manipulate is pretty slippery, so as a general rule you'll want to avoid large strings. But in scenarios where you know you need potentially large strings and where you can easily build up strings sequentially wwFileStream is a great way to build a large string on disk that can then be read into a variable for final processing or passing around as long as that variable itself is not changed.

Well, that only took 30 years to figure out 😃

+++ Rick ---

© 1996-2024