FIle Upload to Pocketbase

Describe the problem/error/question

Trying to upload a file to a pocketbase database.
I tried all kinds of different versions to get a binary file i get from a webhook to upload. hitting a bad request error. (or source.on, or [object object] …

cannot get the file uploaded. tried form data, binary n8n, with all kinds of different setups … im hitting a wall here… please help - thanks!

(i simplified the setup to get closer to the source. normal record creating works - just as soon as I try to send the file to the file field it does not)

What is the error message (if any)?

Problem in node ‘Upload file‘
Bad request - please check your parameters

400 - "{\"code\":400,\"message\":\"Failed to create record.\",\"data\":{}}\n"
Request

{ "headers": { "accept": "application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7", "content-type": "multipart/form-data; boundary=--------------------------626592690690636155903308" }, "method": "POST", "uri": "http://host.docker.internal:8090/api/collections/files/records", "gzip": true, "rejectUnauthorized": true, "followRedirect": true, "resolveWithFullResponse": true, "followAllRedirects": true, "timeout": 300000, "formData": { "file": { "value": { "type": "Buffer", "data": [ 137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 2, 208, 0, 0, 3, 132, 8, 6,

Please share your workflow

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.67.1
  • Database (default: SQLite): sqlite
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: macos 15.1

I figured out, that binary data is only available at the next node, and can not be accessed multiple nodes down the road. this is something that GPT does not know and showed me that the AI is not the solution for all our problems - but more a creator of hours of wasted time trying to fix …

anyway … a write to disk and read from disk node helped.

also the HTTP request node needed the Response Option - and it works when i turn on both options there …

it would really be great if the binary data could stay alive in the buffer and be accessible throughout the workflow.

i tried merge node - but that did not really work … writing/reading is the only way i can manage - even though the data is alive in a temp folder … so it really would be great if that would be changed … also someone should tell openAI

Hey @dukevannori , I suspect your HTTP request is missing something that the API expects. For example, it might need a special headers, or the property should be named somewhat differently instead of “file”. You need to check the API doc to see what might be missing in your request payload.

You can test your workflow on a different API such as https://webhook.site, for example. You should see it works fine (you might want a smaller file size for that).

thank you @ihortom , as i mentioned the mistake was to expect the binary to stay “alive” inside the workflow - but it did not … so whatever i tried it did not upload a correct data.

and with all that i had tried so many different combinations that i could not see light of day.

also important was to add the response option

SO: data files dont stay active for some reason … even if you test the workflow step by step the binary gets lost after execution.

so the only way to do this is to let the workflow execute - and in the worst case needs a write/read file node package to make the data available…

this would be great if it could be handled differently - somehow being able to have binary data active for at least until the workflow runs again.

Hey all. I wanted to post my own update to this problem because I was equally tearing my hair out for hours but found the solution.

The way @dukevannori set up his workflow is perfect. The only thing missing is in the $binary object, in my case where I was getting the binary back from an API call, there was no ‘fileName’ field, so Pocketbase was rejecting it. I also didn’t need the response options, but they helped diagnose the problem so thanks Duke for that.

I added a code node between the API call to retrieve the file and the HTTP request to Pocketbase:

// Add a filename to the binary data
$input.item.binary.data.fileName = 'someName.someExtension'; 

// Return the updated item
return $input.item;

Then using form data and the ‘n8n binary’ option in the HTTP request node worked perfectly. Hope this helps someone else before they go mad :sweat_smile:

1 Like

@dukevannori how are you uploading files, i tried the community node n8n-nodes-pocketbase , but doesnt allow to send files, so i dont know how to use the sdk inside a code node or in a different way. Did you have any luck ?

i use the http request node to send files as binary in form data to the API

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