Uploading file http put request

Hi everyone I need some help after struggling with a topic I'm not familiar with. I want to upload a jpg to a one off signed url which I receive through mqtt. It needs to be through a PUT method. Does anyone have a working example?

The node-red cookbook has some examples to get you heading in the right direction. Give it a go & if you get stuck, pop back with details.

thanks @Steve-Mcl i have seen and imported most of these. Most are http-in and the part I'm stuck on is how to attach a binary file. I'm also not sure if the authentication info that's part of the signed url ("X-Amz-Algorithm" for instance) need to be split off and sent as I dividual headers.id love to avoid having to parse the url that way.

Your probably going to have to get to grips with the Amazon docs for that. There are no prior posts on this matter. Maybe someone has already approached this and can help?. I have not I'm afraid.

how about the file upload? I suspect that leaving the security info in the url will work - but I need to be able to attach a file.

Have you tried setting payload as described in the help?

image

I would guess it needs to be a buffer that contains the image data. (but I dont know the system you are sending it to)

That's where I'm stuck - what does it mean to send something as a buffer and how do you do that...

Where is the jpg - in a file? received from mqtt? from another URL?

In other words, how do you load the jpg image into node red? Show me.

Also, attach a debug node the node that gets the jpg - what does the payload look like in the debug window?

PS

As you dont reply to my comment using the reply button at the bottom of my response (and instead you use the general reply button at the bottom of the thread) I have no idea you have responded to me - as i dont get a notification.

Oops thanks for letting me know @Steve-Mcl . Hard to see the difference on my phone. The jpg is on the same raspberry pi that serves nodered. It's a snapshot from a camera created by an external function that's called earlier in the flow and that passes on the filename. So I have access to it but don't know what to do with it to get it to be part of the http put request.

Use a file in node (set to return a buffer). The msg coming out of the file node will be a binary (Buffer) representing the file.

Question - what is this external function that grabs the image? What kind of camera is it?
The reason I ask is, there is possibly a solution that doesn't need to write to the file system (all done in memory) - this has the benefit of avoiding unnecessary file write (save the SD) and faster / cleaner solution.

It's an esp32. I could do the processing on the esp32 but I prefer to use esphome / home assistant to manage all devices.

so how do you transmit the image to node-red? what node does the image arrive in?

The home assistant automation platform runs on the same server and the file system is accessible by both it and nr. I send a request with nr to ha to store a snapshot - with the rename as parameter so I can find it later on.

ok, fair enough, not how i would approach it but each to their own.

So have you managed to use a file in node and load the file into a msg payload?

Not yet - when I'm back home

And no not the ideal setup if viewed in isolation but it's one of many devices and I want to minimise logic directly on the device. Thanks for the help I will post the result for others once I have it working.

1 Like

It works w http out node. File in node creates a buffer from the local file and sets it as payload. No need to parse the URL for headers I just leave them in msg.url (filename as well), only a header w image type jpeg. Thanks for the help!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.