- Subscribe to RSS Feed
- Mark Question as New
- Mark Question as Read
- Float this Question for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
ListenHTTP processor
- Labels:
-
Apache NiFi
Created ‎12-02-2016 12:29 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I want to send a file over http to nifi. When i do so, the filename attributes is set to a long sequence of numbers as shown below in the picture. How should my http url be?
this is the code im working with
Code Sample as below:
public string PutNifi(string filePath) { // Create a http request to the server endpoint that will pick up the // file and file description. string Message = "Failed"; try { HttpWebRequest requestToServerEndpoint = (HttpWebRequest)WebRequest.Create("http://db-hdf:8081/contentListener"); string boundaryString = "----SomeRandomText"; string fileUrl = filePath; // Set the http request header \\ requestToServerEndpoint.Method = WebRequestMethods.Http.Post; requestToServerEndpoint.ContentType = "multipart/form-data; boundary=" + boundaryString; requestToServerEndpoint.KeepAlive = true; requestToServerEndpoint.Credentials = System.Net.CredentialCache.DefaultCredentials; // Use a MemoryStream to form the post data request, // so that we can get the content-length attribute. MemoryStream postDataStream = new MemoryStream(); StreamWriter postDataWriter = new StreamWriter(postDataStream); // Include the file in the post data postDataWriter.Write("\r\n--" + boundaryString + "\r\n"); postDataWriter.Write("Content-Disposition: form-data;" + "name=\"{0}\";" + "filename=\"{1}\"" + "\r\nContent-Type: {2}\r\n\r\n", "myFile", Path.GetFileName(fileUrl), Path.GetExtension(fileUrl)); postDataWriter.Flush(); // Read the file FileStream fileStream = new FileStream(fileUrl, FileMode.Open, FileAccess.Read); byte[] buffer = new byte[1024]; int bytesRead = 0; while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) { postDataStream.Write(buffer, 0, bytesRead); } fileStream.Close(); postDataWriter.Write("\r\n--" + boundaryString + "--\r\n"); postDataWriter.Flush(); // Set the http request body content length requestToServerEndpoint.ContentLength = postDataStream.Length; // Dump the post data from the memory stream to the request stream using (Stream s = requestToServerEndpoint.GetRequestStream()) { postDataStream.WriteTo(s); } postDataStream.Close(); Message = "Success"; } catch (Exception ee) { Message = ee.ToString(); } return Message; } }
Created ‎12-02-2016 02:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you send a header named "filename" it should respect that value for the filename attribute in NiFi:
Basically HTTP headers become FlowFile attributes, and the body of the HTTP request becomes FlowFile content.
Write now it looks like you are writing the filename into the body of the POST request.
Created ‎12-02-2016 02:28 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you send a header named "filename" it should respect that value for the filename attribute in NiFi:
Basically HTTP headers become FlowFile attributes, and the body of the HTTP request becomes FlowFile content.
Write now it looks like you are writing the filename into the body of the POST request.
Created ‎12-05-2016 08:51 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you it worked
