New post

Rechercher

Article
· Mar 4 2m read

ObjectScriptを使用し、ローカルファイルを他のサーバーにアップロード(POST)する方法

これは InterSystems FAQ サイトの記事です。
 

ObjectScriptの%Netパッケージのライブラリクラスを利用して、ファイルを他のサーバーにアップロードすることができます。

以下のCurl コマンドと同じことを ObjectScript で実現する方法を紹介します。

curl -X POST "http://localhost/api/upload?a=123&b=999" -F file=@"C:/temp/a.csv"

クライアントのObjectScriptコードを以下の様に作成します。

  // form-data (for CSV)
  set msg= ##class(%Net.MIMEPart).%New()

  set msg.ContentType = "multipart/form-data"
  set inputstream=##class(%Stream.FileCharacter).%New()
  set sc=inputstream.LinkToFile("C:\temp\a.csv")
  If $$$ISERR(sc) Do $system.OBJ.DisplayError(sc) Quit
  set filePart = ##class(%Net.MIMEPart).%New(inputstream)
  set filePart.ContentType = "text/plain"
  do filePart.SetHeader("Content-Disposition","form-data; name=""csvfile""; filename=""upload.csv""")
  do msg.Parts.Insert(filePart) 
  set tempstream = ##class(%Stream.TmpCharacter).%New()

  set writer = ##class(%Net.MIMEWriter).%New()

  do writer.OutputToStream(.tempstream)

  do writer.WriteMIMEBody(msg)

  // POST with the above form-data
  set req=##class(%Net.HttpRequest).%New()

  set req.Server="127.0.0.1"
  set req.Port=80
  do req.SetParam("a","123")   ;; a=123
  do req.SetParam("b","999")   ;; b=999
  set req.EntityBody = tempstream

  set req.ContentType = "multipart/form-data; boundary="_msg.Boundary

  set sc = req.Post("/api/upload")

  If $$$ISERR(sc) Do $system.OBJ.DisplayError(sc) Quit
  set res=req.HttpResponse

  write res.Data.Read(1000)
Discussion (0)1
Log in or sign up to continue
Question
· Mar 4

Debugging embedded python library

I have an Embedded Python method, which is essentially a call to one third-party module.

Most of the time, the method takes <0.1 seconds to execute, but sometimes it takes 30 or 60 seconds.

The server is relatively idle (20-30% CPU load).

How can I debug this issue further? Ideally, I want to know where this library spends the time. The library is mainly Python code (it's boto3, so it's not a Python C API proxy library).

2 Comments
Discussion (2)2
Log in or sign up to continue
Question
· Mar 4

Using Lists and ListFind within BPL

I already mentioned in a Previous post I am trying to build a list from a repeatable field within a HL7 message. I figured out how to build the list by using a context list string variable within the Business Process (BPL) and doing a

do context.<variable>.Insert = <value>

 when I am looping through the field. I want to do it one step farther though... I want to search the list to see if the value exists before I do the insert. I only want to insert if the value is different than what is in the list already.

IF $LF(context.Facilities,##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4)) = 0
{
do context.Facilities.Insert = ##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4)
}

I tried using $LF or $LISTFIND, but I keep getting the same error...

ERROR <Ens>ErrBPTerminated: Terminating BP EpicMFNToCPD # due to error: ERROR <Ens>ErrException: <LIST>S36+3 ^osuwmc.Epic.MFN.EpicMFNToCPD.Thread1.1 -- logged as '-'
number - @'
IF $LF(context.Facilities,##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4)) = 0'
> ERROR <Ens>ErrException: <LIST>S36+3 ^osuwmc.Epic.MFN.EpicMFNToCPD.Thread1.1 -- logged as '-'
number - @'
IF $LF(context.Facilities,##class(Ens.Rule.FunctionSet).SubString(context.EpicDepartmentID,1,4)) = 0'

Any guidance would be appreciated.

1 Comment
Discussion (1)1
Log in or sign up to continue
Question
· Mar 4

Using Lists - LB and LI

I have a repeatable field within HL7 that I want to create a List from. Do I have to initialize the List by using $LB, or can I just use $LI to keep adding on to the end of the list as it is looping through the field?

4 Comments
Discussion (4)1
Log in or sign up to continue
Question
· Mar 4

NodeJS Iris Package - Work on node Windows?

Hello, Does the NodeJs package work when running a node js file on windows (nodejs for windows)? I've added the package by running npm install <package location folder>

 

I have the following index.js file, but when running from node (windows) I get the following error. Does the NodeJs package build the output files when the package is added or does it just assume linux as the underlying os?

Error: Cannot find module './bin/winx64/irisnative.node'

 const IRISNative = require('intersystems-iris-native')

  let connectionInfo = {
    host: 'myserver',
    port: 1972,
    ns: 'USER',
    user: 'user',
    pwd: 'password',
    sharedmemory: true,
    timeout: 5,
    logfile: '.\\mylogfile.log'
  };

  const conn = IRISNative.createConnection(connectionInfo);
5 Comments
Discussion (5)4
Log in or sign up to continue