Web Connection
Upload file by multipart-form
Gravatar is a globally recognized avatar based on your email address. Upload file by multipart-form
  Yonggu
  All
  Feb 28, 2019 @ 01:41am

Hi.

In my vfp desktop application, I uploaded a file with wwHttp.

In wwProcess on application server, get the file stream and save to file.

In file based, Everything's good.

In com server mode, the file is created but, I can't open it.

Do you know why?

Gravatar is a globally recognized avatar based on your email address. re: Upload file by multipart-form
  Rick Strahl
  Yonnggu
  Feb 28, 2019 @ 02:47pm

No - should work exactly the same unless there's a permissions problem and somehow the file isn't closed. Make sure when you write it out however you do it you close the file.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Upload file by multipart-form
  Yonggu
  Rick Strahl
  Feb 28, 2019 @ 04:05pm

I don't know why it is happening.

AS I told you, it only happens in com server mode.

SET DEFAULT TO c:\temp

LOCAL lcFileName
lcFileName = GETFILE()

DO wwHttp

oHttp = CREATEOBJECT("wwHTTP")

*** Set mode to multi-part form
oHttp.nHttpPostMode = 2

*** Post a file and a regular form variable
oHttp.AddPostKey("File", lcFileName, .T.)
oHttp.AddPostKey("cFileMemo","test")

lcHTML = oHTTP.HTTPGet("http://localhost/wwDemo/FileUpload.wwDemo")

*** Display result from server
ShowHTML(lcHTML)  && Image is there but not rendering because of relative path

*********************************************************************
FUNCTION FileUpload
*********************************************************************
LOCAL lcFileName, lcFileBuffer, lcFileMemo

lcFileName = ""
lcFileBuffer = REQUEST.GetMultiPartFile("File", @lcFileName)
lcFileMemo = REQUEST.GetMultiPartFormVar("cFileMemo")

lcFileName = "C:\temp\" + JUSTSTEM(lcFileName) + "_rerult." + JUSTEXT(lcFileName)

IF LEN(lcFileBuffer) = 0
   THIS.StandardPage("Upload Error","An error occurred during the upload or the file was too big.")
   RETURN
ENDIF

IF LEN(lcFileBuffer) > 500000
   THIS.StandardPage("File upload refused",;
                     "Files over 500k are not allowed for this sample...<BR>"+;
                     "File: " + lcFilename)
   RETURN
ENDIF

*** Now dump the file to disk
File2Var(lcFileName, lcFileBuffer)

THIS.StandardPage("Thank you for your file upload",;
                  "<b>File Uploaded:</b> " + lcFileName + ;
                  " (" + TRANSFORM(FileSize(lcFileName),"9,999,999") + " bytes)<p>")


ENDFUNC
* FileUpload

Gravatar is a globally recognized avatar based on your email address. re: Upload file by multipart-form
  Rick Strahl
  Yonnggu
  Feb 28, 2019 @ 05:13pm

I don't know why it wouldn't work - there's no difference in how those files are processed between file and COM modes, so it's gotta be something else than the processing.

I would check and see what the size of content is and maybe compare the HTTP output that is sent. Are you sure you're sending the same data when you're comparing? Use Fiddler to compare the size and content of the data being sent in each case.

Do make sure you're not writing the same file you are sending 😃

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Upload file by multipart-form
  Yonggu
  Rick Strahl
  Feb 28, 2019 @ 05:39pm

Thanks for the quick reply.

I think that it's a matter of encoding.

My application has been working about 12 years without any problem in file based message.
As time goes by, people who use my application increased and an unknown error started to occur.

Some days ago, I decided to change from file based message to com message.

In com message, everything is going well except handling files (jpg, png, pdf, zip etc.).
I have to solve the problem.

Here is an alternative I think and it works in file based message and com message.
But, I don't know there is any problem I didn't consider.

How about you?

SET DEFAULT TO c:\temp

LOCAL lcFileName
lcFileName = GETFILE()

*DO FileUpload WITH lcFileName
DO FileUpload_Test WITH lcFileName



FUNCTION FileUpload
LPARAMETERS tcFileName

DO wwHttp

oHttp = CREATEOBJECT("wwHTTP")

*** Set mode to multi-part form
oHttp.nHttpPostMode = 2

*** Post a file and a regular form variable
oHttp.AddPostKey("File", tcFileName, .T.)
oHttp.AddPostKey("cFileMemo","test")

lcHTML = oHTTP.HTTPGet("http://localhost/wwDemo/FileUpload.wwDemo")

*** Display result from server
ShowHTML(lcHTML)  && Image is there but not rendering because of relative path

ENDFUNC 

FUNCTION FileUpload_Test
LPARAMETERS tcFileName

LOCAL lcFileBuffer
lcFileBuffer = FILETOSTR(tcFileName)
lcFileBuffer = STRCONV(lcFileBuffer, 13) && Converts single-byte characters in cExpression to encoded base64 binary

DO wwHttp

oHttp = CREATEOBJECT("wwHTTP")

*** Post a file and a regular form variable
oHttp.AddPostKey("cFileName", JUSTFNAME(tcFileName))
oHttp.AddPostKey("cFileBuffer", lcFileBuffer)

lcHTML = oHTTP.HTTPGet("http://localhost/wwDemo/FileUpload_Test.wwDemo")

*** Display result from server
ShowHTML(lcHTML)  && Image is there but not rendering because of relative path

ENDFUNC 
*********************************************************************
FUNCTION FileUpload
*********************************************************************
LOCAL lcFileName, lcFileBuffer, lcFileMemo

lcFileName = ""
lcFileBuffer = REQUEST.GetMultiPartFile("File", @lcFileName)
lcFileMemo = REQUEST.GetMultiPartFormVar("cFileMemo")

lcFileName = "C:\temp\" + JUSTSTEM(lcFileName) + "_rerult." + JUSTEXT(lcFileName)

*lcFileName = "C:\temp\update\" + lcFileName

IF LEN(lcFileBuffer) = 0
   THIS.StandardPage("Upload Error","An error occurred during the upload or the file was too big.")
   RETURN
ENDIF

IF LEN(lcFileBuffer) > 500000
   THIS.StandardPage("File upload refused",;
                     "Files over 500k are not allowed for this sample...<BR>"+;
                     "File: " + lcFilename)
   RETURN
ENDIF

*** Now dump the file to disk
File2Var(lcFileName, lcFileBuffer)

THIS.StandardPage("Thank you for your file upload",;
                  "<b>File Uploaded:</b> " + lcFileName + ;
                  " (" + TRANSFORM(FileSize(lcFileName),"9,999,999") + " bytes)<p>")


ENDFUNC
* FileUpload

*********************************************************************
FUNCTION FileUpload_Test
*********************************************************************
LOCAL lcFileName, lcFileBuffer

lcFileName = REQUEST.Form("cFileName")
lcFileBuffer = REQUEST.Form("cFileBuffer")
lcFileBuffer = STRCONV(lcFileBuffer, 14) && Converts base64 encoded data in cExpression to original unencoded data.

lcFileName = "C:\temp\" + JUSTSTEM(lcFileName) + "_result." + JUSTEXT(lcFileName)

IF LEN(lcFileBuffer) = 0
   THIS.StandardPage("Upload Error","An error occurred during the upload or the file was too big.")
   RETURN
ENDIF

IF LEN(lcFileBuffer) > 500000
   THIS.StandardPage("File upload refused",;
                     "Files over 500k are not allowed for this sample...<BR>"+;
                     "File: " + lcFilename)
   RETURN
ENDIF

*** Now dump the file to disk
File2Var(lcFileName, lcFileBuffer)

THIS.StandardPage("Thank you for your file upload",;
                  "<b>File Uploaded:</b> " + lcFileName + ;
                  " (" + TRANSFORM(FileSize(lcFileName),"9,999,999") + " bytes)<p>")


ENDFUNC
* FileUpload_Test
Gravatar is a globally recognized avatar based on your email address. re: Upload file by multipart-form
  Rick Strahl
  Yonnggu
  Feb 28, 2019 @ 06:14pm

I don't know, i have no idea.

I'm using file uploads in COM mode without any problems, here on the message board, in the samples and a few other places so I know it works. Whatever is happening must be specific to the environment. I would capture the output and compare trying to figure out what the differences are between the data that comes in the different modes.

+++ Rick ---

© 1996-2024