Support Questions
Find answers, ask questions, and share your expertise

ExecuteScript Processor - InputStream not being sent to web API

ExecuteScript Processor - InputStream not being sent to web API

New Contributor

I have a Python script within an ExecuteScript processor and am trying to upload the contents of the flow file to an API that expects multipart/form data.  The script is using the requests object to post the request; however, the contents of the flow file does not get sent to the API.  Below is the script:



import sys
import json
import requests
from import InputStreamCallback
from import IOUtils

# Define a subclass of InputStreamCallback for use in
class PyInputStreamCallback(InputStreamCallback):
  def __init__(self):
  def process(self, inputStream):
        length = flowFile.getSize()
        log.warn("MyLog >> File length: " + str(length))
        multipart_form_data = {'file': ('test.xml', inputStream, 'text/xml')}'http://url/api/uploadfile', files=multipart_form_data)
# end class

flowFile = session.get()
if(flowFile != None):, PyInputStreamCallback())
    session.transfer(flowFile, REL_SUCCESS)



I have verified that the inputStream has data, but the data is not sent to the API when called within NiFi.  If I run the script outside of NiFi and just read the file from the file system, it works correctly.


Is there something else that needs to be done to send the flowFile?

Don't have an account?