guides:oecgi4:uploading_files_via_oecgi4

Uploading files via OECGI4

You can upload files via a web browser to your OpenInsight application via OECGI4. There are two registry settings that control file uploads.

Registry SettingValue
FileModeThere are 3 possible settings:

1 = upload file to the directory specified in FilePath, and delete it when the OECGI4 request is completed.
2 = upload file to the directory specified in FilePath
3 = upload the file directly to OpenInsight. You can only upload text files (text, csv, xml, html etc) via this mode. It does not support binary files like images or pdf’s. Use mode 1 or 2 for binary file types.

Note: For modes 1 & 2, OECGI4 will assign a temporary filename to the file physically located in the FilePath. The name of the temporary file will be passed to OpenInsight in the request string and accessible via INET_QUERYPARAMS
FilePathThe directory where the file will be uploaded for modes 1 & 2. This path is relative to the directory where OECGI4.EXE is located.

Example 1:

OECGI4.EXE is located in c:\inetpub\scripts

FilePath is set to upload\

In this scenario OECGI4 will upload the file to c:\inetpub\scripts\upload

Example 2:

OECGI4.EXE is located in c:\inetpub\scripts

FilePath is set to \upload\

In this scenario OECGI4 will upload the file to c:\inetpub\upload

Note 1: You must add a backslash \ to the end of the FilePath setting.

Note 2: You must enable write permissions to the upload directory specified in FilePath.

Note 3: FilePath is ignored when FileMode is set to 3

Table 2 - File upload registry settings.

Here is an example of the registry settings for:

FileMode = 2

FilePath = c:\Revsoft\OInsight\o4w\uploads\

These settings will upload a file to the c:\inetpub\upload directory on the web server and will delete the file once your inet procedure has completed.

UNICODE��L�E�A�D� �T�e�c�h�n�o�l�o�g�i�e�s� �I�n�c�.� �V�1�.�0�1

Figure 41 - Registry settings for FileMode 2

Below is an example HTML page which will upload a file to OpenInsight via OECGI4. File uploads in HTML are handled by a form tag and the input tag with the type set to file. Please note the enctype attribute in the form element. You need to set this element as per the example so that your web server will upload the file.

<html>

<body>

<form name="myform" action="\o4w\OECGI4.exe\inet_myloadproc" method="POST"  enctype="multipart/form-data">

<input name="myfilename" type="file" size="50">

</form>

</body>

</html>

Figure 42 - Sample HTML markup for file uploads

The BASIC+ code for the inet_myloadproc Stored Procedure is below.

Function inet_myuploadproc(request)

 

// Sample code to demonstrate how to upload a file to OpenInsight via OECGI4

 

declare function inet_queryParam

// set the upload directory

uploadDir = “c:\inetpub\upload\”

 

// For FileMode = 1 & 2

// Get the name of the file the user uploaded to us

orig.filename = inet_queryparam(request,”myfilename”)

 

// You should always sanitize data from the web to protect

// against script injections, bad filename uploads etc

filename = iconv(orig.filename,”[URL_FORMAT]”)

 

// Get the name of the file stored in the directory specified in FilePath

uploadedFileName = inet_queryparam(request,”myfilename_filename”)

 

// Now copy the uploaded file to somewhere on our server so that we can process it

osread data from uploadDir:uploadFileName then

    oswrite data on drive():”\”:filename

end

 

// For FileMode = 3

// The actual data file is passed to us via the request string

data = inet_queryparam(request,”myfilename”)

 

return “thanks for uploading your file to us”

Figure 43 - Example BASIC+ code inet_myuploadproc.

Note 1: FileMode = 2 will delete the temporary file from the upload directory after your BASIC+ procedure completes.

Note 2: We did not create an input tag in our html page with the name of myfilename_filename. This is added to the request string by OECGI4 to pass you the temporary filename it created in the upload FilePath directory.

  • guides/oecgi4/uploading_files_via_oecgi4.txt
  • Last modified: 2023/10/25 10:49
  • by 127.0.0.1