Question about WebUploadedFile data

I am using a WebFileUploader to read in a text file from a client.

[code]
dim csvData as string

For Each file As WebUploadedFile In files
csvData = file.Data
next[/code]

I believe assigning the data to the csvData may have been a mistake.
It may be that it works but I suspect that the string encoding is not set properly and is causing issues in my application at a later date.
It’s a simple text file with dos or unix carriage return line feeds… it might contains some foreign characters like japanese or chinese…

I suspect I was suppose to take file.Data and put it into a binarystream before using it…

The long story short is this all works great in 32 bit mode but in 64 bit mode I believe it causes an exception to be raised within a completely different method.

Any thoughts?

Brian, I’m still thinking about this in the other thread. Does the program throw the error if you don’t read the data in, ie. if you comment out csvData = file.Data above?

If it does then the problem lies elsewhere (check for race conditions, make sure your timers/threads are safe)

If it doesnt then you’ll need to convert the string to something you can safely use, try playing around with

csvData = ConvertEncoding(file.Data, Encodings.WindowsANSI)

Good luck, I have to get some zzz’s. I’ll see how you got on in the morning.

Ps. With a lack of a debugger in 64b, commenting code and debug log every step is the best you can hope for

If I dont have csvData then no object will be created…
I’ll try the encoding.

no help… it’s still crashing.

Have you implemented the UnhandledException events to see where the problem actually is?

I think I’ve figured out that it has something to do with me using

FileName = FileNames(0)

as the title for my web page.

I catch the exception in an odd place…

In Process File
An exception of type xojo.Core.BadDataException was caught.
String must have a known encoding
String must have a known encoding
_pthread_body
rbframework.dylib$1192
_HTTPServer.HTTPRequestThread.Event_Run%%o<_HTTPServer.HTTPRequestThread>
WebApplication._HandleHTTPRequest%%o<WebApplication>o<_HTTPServer.HTTPRequestContext>
WebSession._HandleRequest%i8%o<WebSession>so<_HTTPServer.HTTPRequestContext>
WebFileUploader._SetFiles%%o<WebFileUploader>A1o<WebUploadedFile>
AddHandler.Stub.32%%A1o<WebUploadedFile>
Delegate.IM_Invoke%%o<WebFileUploader>A1o<WebUploadedFile>
FileSelectContainerControl.FileSelectContainerControl.FileUploader_UploadComplete%%o<FileSelectContainerControl.FileSelectContainerControl>o<WebFileUploader>A1o<WebUploadedFile>
AddHandler.Stub.40%%A1sA1v
Delegate.IM_Invoke%%o<FileSelectContainerControl.FileSelectContainerControl>A1sA1v
WebPageMain.WebPageMain.FilesUploadedMethod%%o<WebPageMain.WebPageMain>o<FileSelectContainerControl.FileSelectContainerControl>A1sA1v
WebPageMain.WebPageMain.ProcessFile%%o<WebPageMain.WebPageMain>
UMLSequenceController.AddMessage%%o<UMLSequenceController>o<Message>
MessageView.MessageView.Constructor%%o<MessageView.MessageView>
WebControl._SetDimensions%%o<WebControl>i8i8i8i8&A1o<WebControl>
WebCanvas.Event_Resized%%o<WebCanvas>
WebCanvas._UpdateCanvasSize%%o<WebCanvas>
WebSession._Update%%o<WebSession>
WebPushHandler.!PushBySession%%o<WebSession>
WebPushHandler.Respond%%o<WebPushHandler>
WebSession._CreateResponse%o<WebResponse>%o<WebSession>
WebObject._Render%o<WebSource>%o<WebObject>i8
WebControl.Event_RenderPropertyChange%b%o<WebControl>svo<WebSource>
WebView.Event_RenderPropertyChange%b%o<WebView>svo<WebSource>
WebPage.Event_RenderPropertyChange%b%o<WebPage>svo<WebSource>
WebSource.Append%%o<WebSource>si8b
_WebSupport.Split%A1s%ss
String.$ToText%y%s
String_ToText
rbframework.dylib$2112
App is shutting down: Request shutdown

Commenting out the line Filename = FileNames(0)
and never using it later seems to make the Exception go away.

[code]Private Sub FilesUploadedMethod(c as FileSelectContainerControl, FileNames() as string, rows() as Variant)
System.DebugLog(“FilesUploadedMethod”)

redim Session.logLines(-1)

//FileName = FileNames(0) // This causes issues.

for i as integer = 0 to rows.Ubound
session.logLines.Append rows(i)
next

System.DebugLog(“Log loaded”)

ProcessFile
System.DebugLog(“File Processing done”)

End Sub[/code]

Well, you’re getting text from an outside source and you should always set an encoding if you can. I see where it’s dying and it’s a bug, but you can probably solve this by setting the encoding on that filename property before sending it back to the page.

I’ve never quite understood the text encoding methods in Xojo.
I get the idea, it’s a string, but maybe its utf8 or maybe its utf16…
but I don’t get how I’m suppose to set the encoding property.

If you’re defining both sides of the equation then you know because you wrote it. If you’re dealing with another vendor on the other end, you’d get that info from them. For instance the web framework tells browsers to work in UTF8, so you can probably use DefineEncoding and set that string to Encodings.utf8 and have it just work.

Well this is about as close as I come to being able to reproduce this issue.
The application works perfectly in the debugger in 32 bit mode.
When I build the 64 bit stand alone web app it hangs.
I haven’t been able to trap the exception in this but it behaves the same without being able to catch the exception.
Sample Project

I’m pretty sure I was tired when I wrote this so if you see anything wonky in the event handling between the file up load / the session and the web page…

I didn’t look at your code (so just guessing) but are you using string .Split’s somewhere?
With 64 bit desktop Apps, I ran into all kind of Encoding issues and random issues with string .Split’s.

(If I remember correctly,) I was able to fix the Split issues by converting strings into Text first.
See at the bottom under ‘Current Known Issues’ here: http://developer.xojo.com/64-bit-guidelines

I wasn’t able to fix the encoding issues. <https://xojo.com/issue/41636>

Hi Brian. I tried your code and I could upload a log file without problem in 64bit standalone. I suspect its an encoding issue with the log file you’re using, would you be able to post a link to it or upload it or a sample that errors? Thanks

@Marco Yes I use split to divide a text file into lines.
@Julian I replicated the issue on my MAC. With the above project. What 64 bit stand alone (not cgi) platform did you build and run?

Yes, I built and ran in W10 x64, standalone port 8080. What file did you upload with, or did the error show before you even uploaded?

If you uploaded a file, I think I’ll need a copy of that so I can test it with the same file as it might have some strange chars in.

Sorry Julian but did you say you ran in Windows?
I’m not running in the debugger I built the app for Mac OS X standalone on port 80
Keep in mind that the build setting for 32 bit allow this to run in the debugger and as a stand alone application without issues.

There is absolutely no way for me to share the actual files I am testing with without landing my self in jail, bad enough i have to share source code…

I will have to try to make something that resembles it.
It is essentially text file with 0x0D 0x0A as carriage return line feeds.

Yes, I am testing in Windows10 at the moment, if I can replicate it here we’ll know its a framework problem and not a coding issue.

I can drop in to OSX if/when I can replicate it. If I cant, I’ll go in there anyway and run the same test that works on Win10 x64

To do some testing with that example file:

  1. Create a 1 line file , visually inspect it to make sure it doesnt have any non-utf8 chars in there - and run it through your program

If this doesnt blow up then move on to step 2

  1. Create a 2 line file with a copy of the line above separated with CRLF (0x0D 0x0A) - run it through your program

If this doesnt blow up then its not a problem with the split

  1. Check your original file for non-utf8 chars and paste one of those in on line 1 - run it through your program

If this doesnt blow up then let me know and I’ll come up with some more text cases

  1. If using Strings, convert String to Text and split that with something like inputAsText.Split(EndOfLine.UNIX)

@marco. Can you give me an example of converting a string to Text?

[quote][/quote]The thing I can’t understand is that the line
FileName = FileNames(0)

Seems to be the problem. That one line of code sets off a whole change in behaviour in the whole project.
(This is apparently very visible in the stack dump I provided, although I do not recognise the internal)

Looking at the example project does it seem structurally correct to you?
I took this from an example project and morphed it a bit to suite my needs but I hate the way there is data that is in the session and methods in the control. I’m not sure why things aren’t all in the WebPage class…

Assuming FileName is of type Text, try it like this:

FileName = FileNames(0).ToText

Now you may still get an error if Filenames(0) has no encoding for some reason (or an invalid one perhaps).

[quote=268575:@Greg O’Lone]Assuming FileName is of type Text, try it like this:

FileName = FileNames(0).ToText

Now you may still get an error if Filenames(0) has no encoding for some reason (or an invalid one perhaps).[/quote]

Its a String Property in the same Method