0
votes

i have an expression bellow to read a file from resources :

#[Thread.currentThread().getContextClassLoader().getResourceAsStream('abc.txt')]

it worked fine, but i want to use a variable like this one:

#[Thread.currentThread().getContextClassLoader().getResourceAsStream(flowVars['fileName'])]

it does not work,

  1. how can i make it work like the first one MEL ?
  2. how can i read a file in absolute path "D://input/abc.txt" using MEL ?

Thanks for helps.

resolved

  1. use flowVars.filename instead of flowVars['fileName'] it worked, but i can't get it, i use logger with this MEL #[flowVars['filename']] and it work too but in the second MEL it failed.
2
seems correct to me, what error are you getting?Avanaur
the second MEL return null payload, the first one return a file as streamNhanHo
I tried reproducing this and both the first and second mel's return a java.io.BufferedInputStream, which is expected.Sudarshan
a second MEL worked with flowVars.filename, thanks. Can you take a look to 2nd question.NhanHo
You are using a different case with the two different approaches. Variable names are case sensitive.Ryan Carter

2 Answers

0
votes

1) You are using a different case with the two different approaches. Variable names are case sensitive.

2) Just use a FileInputStream:

 #[new FileInputStream("path")]

Or even better maybe to use the File transport/Mule Requester Module.

-1
votes

Try this, Use variable name instead of using keyword "flowVars"

#[Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName)]