Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Uploading a single file using File Upload UI to NiFi

avatar
Explorer

Hi

I am trying to upload a file from UI and the content is received in NiFi but I am not able to maintain the filename. I am getting the filename as some integer which is by convention of the Flow file message attribute is correct. But Is there a way where I can maintain the file name, same as the file I have uploaded from UI.

Regards

S A Hameedh

3 REPLIES 3

avatar
Master Guru

How are you uploading the file? Processors like GetFile will set the filename attribute to the same name that was on disk.

avatar
Explorer

Hi Matt,

I am using postman and in the body I am uploading a file.

Regards

S A Hameedh

avatar

@Hameed Abdul

This is the expected behavior. Your file name is local to your client environment and NiFi have no clue on where it comes from. You need to send this information together with your file. The number that you are seeing is the ID that NiFi generated for this received flow file.

How to send data depends on your client. If I use CURL to upload data I can do

curl --form "fileupload=@/tmp/file1.txt;filename=file1.txt" localhost:7878

and I receive the following in NiFi

--------------------------2c1843649b5760e1
Content-Disposition: form-data; name="fileupload"; filename="file1.txt"
Content-Type: text/plain


this is file 1


--------------------------2c1843649b5760e1--

You can use ExtractGrok or ExtractText to get the filename and update the flow file attribute.

EDIT: As I said, this depends on your client. I did the same test with Postman and here's how to get the right information.

Add a header to your POST query. I added a header called originalfilename

39744-screen-shot-2017-10-10-at-74627-pm.png

I get this information as an attribute of my flow file

39745-screen-shot-2017-10-10-at-74733-pm.png

With this you only need to use UpdateAttribute processor to copy this attribute to filename.

Hope this helps