Member since
06-09-2023
5
Posts
0
Kudos Received
0
Solutions
08-31-2023
02:56 AM
Many thanks @MattWho Yes this is my issue, but the problem I tried to change my above code based on below: import org.apache.commons.io.IOUtils import java.nio.charset.StandardCharsets flowFile = session.get() if(!flowFile)return def text = '' // Cast a closure with an inputStream parameter to InputStreamCallback session.read(flowFile, {inputStream -> text = IOUtils.toString(inputStream, StandardCharsets.UTF_8) // Do something with text here } as InputStreamCallback) to make it reading the flow instead of creating new flow, but a lots of errors any suggestions will be helpful for me thanks in advance
... View more
08-30-2023
01:39 AM
there are no 2 success queues to PutFile, one is incoming to PutFile and the second outgoing to ExecuteScript and the third outgoing from ExecuteScript.
... View more
08-28-2023
01:20 AM
when I am using PutFile Processor and ExecuteScript Processor,the object in the flow between them stuck for longer time than expected and processed many times. this case happend only between these 2 processors only. even if I set the expiration time for the flow and set it to 1 second, and scheduled the run of ExecuteScript to 4 sec, still processing the flow at least 2 times. which cause sending the file to the API many times. the version of the NIFI I am usnig is: NIFI v1.18, also I tried to upgrade and use version 1.22, but this issue still as is. The script I am using in ExecuteScript is: import org.apache.commons.io.IOUtils import org.apache.nifi.processor.io.OutputStreamCallback def flowFile = session.create() def filePath = 'E:/tmp/tmp_file.txt' def file = new File(filePath) if (file.exists()) { def fileContent = IOUtils.toByteArray(new FileInputStream(file)) flowFile = session.write(flowFile, { outputStream -> outputStream.write(fileContent) } as OutputStreamCallback) session.transfer(flowFile, REL_SUCCESS) } else { session.remove(flowFile) // Handle file not found or other error }
... View more
Labels:
- Labels:
-
Apache NiFi
06-09-2023
05:53 PM
Hi, kindly need your support in below, I have Text file, I have to convert it to byteArray and send it through REST API, I tried many ways to convert the file to byteArray, last one is: - ExecuteScript with below code: import base64 import codecs with codecs.open('/path/to/input/file.txt', 'r', encoding='utf-8') as file: file_content = file.read() file_bytes = file_content.encode('utf-8') encoded_bytes = base64.b64encode(file_bytes) encoded_string = encoded_bytes.decode('utf-8') flowFile = session.putAttribute(flowFile, 'fileContent', encoded_string) session.transfer(flowFile, REL_SUCCESS) but still get error: utf-8' codec can't decode byte 0xff in position 0: unexpected code byte in <script> at line number 6 REST API Config: HTTP Method: POST API URL:..... Request Content-Type: application/octet-stream authentication User: username authentication password: password we applied it in VB.net as below: Function CallApi(APIURL As String,filepath As String) As String Dim req As WebRequest = WebRequest.Create(APIURL) Dim txtfile = File.ReadAllBytes(filepath"file.txt") System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications req.Headers("Authorization") = "Basic " & Convert.ToBase64String(Encoding.[Default].GetBytes("username:password")) req.Method = "POST" req.ContentType = "application/octet-stream" Dim byteArray As Byte() = txtfile req.ContentLength = byteArray.Length Dim dataStream As Stream = req.GetRequestStream() dataStream.Write(byteArray, 0, byteArray.Length) dataStream.Close() ' response Dim resp As WebResponse = req.GetResponse() Dim s As Stream = resp.GetResponseStream() Dim sr As StreamReader = New StreamReader(s, Encoding.UTF8) Dim doc As String = sr.ReadToEnd() Return doc End Function Any suggestions may help me to achieve this?
... View more
Labels:
- Labels:
-
Apache NiFi