8000 🐛 Bug Report: Can't createFile via n8n flow · Issue #3313 · appwrite/appwrite · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🐛 Bug Report: Can't createFile via n8n flow #3313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
theMeysam opened this issue May 31, 2022 · 14 comments
Closed
2 tasks done

🐛 Bug Report: Can't createFile via n8n flow #3313

theMeysam opened this issue May 31, 2022 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@theMeysam
Copy link

👟 Reproduction steps

When I try to add file to my appwrite storage by "create file" via API (Curl) it show bellow error:
{ "status": "rejected", "reason": { "message": "500 - {"message":"Server Error","code":500,"type":"general_unknown","version":"0.14.2"}", "name": "Error", "stack": "Error: Request failed with status code 500 at createError REDACTED" } }

👍 Expected behavior

It should add my image to storage

👎 Actual Behavior

ERROR: UNKNOWN ERROR - check the detailed error for more information
Server Error

🎲 Appwrite version

Version 0.14.x

💻 Operating system

Linux

🧱 Your Environment

No response

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

@theMeysam theMeysam added the bug Something isn't working label May 31, 2022
@Meldiron
Copy link
Contributor

Hello there 👋

The problem is most likely related to the chunk uploading mechanism kicking in with direct HTTP communication (not using our SDKs to manage it).

First, let's get details about the error. After getting the 500 error, please run the following command on a device where your Appwrite backend is installed: docker-compose logs appwrite (or docker compose logs appwrite, depending on your installation). That will let us know what exactly is going wrong.

It would also be really valuable to know the exact CURL command you are using, and/or have the file you are trying to upload. These will allow us to reproduce the problem, and easily investigate underlying issues.

@theMeysam
Copy link
Author
theMeysam commented Jun 1, 2022

Hi dear Meldiron

At first:
https://i.ibb.co/C9hSL1y/Screenshot-20220602-021627.jpg
About exact CURL:
I use API 3 json file from here on swaggerhub.com, my test app from Android, from som no code platform like n8n.io and other things.

@stnguyen90
Copy link
Contributor

At first: https://i.ibb.co/C9hSL1y/Screenshot-20220602-021627.jpg

Based on this screenshot, it doesn't seem like the request format is correct. The content type should be multipart/form-data, the name should be file, and the bytes should be the value.

Could you perhaps share your code?

@theMeysam
Copy link
Author
theMeysam commented Jun 4, 2022

@stnguyen90
Thanks for your advice.

In fact I'm low coder person.
I use n8n (n8n.io) for my automation service.
I try to add some screenshots.
I also open issue on n8n community (n8n community).

After your advice I correct some options but I want to know what 8the correct format that I should send to my appwrite server.
fileId: unique(),
file:?

I also attached my new error from my docker compose logs.

appwrite | [Error] Method: POST appwrite | [Error] URL: /v1/storage/buckets/:bucketId/files appwrite | [Error] Type: TypeError appwrite | [Error] Message: {closure}(): Argument #3 ($file) must be of type array, string given, called in /usr/src/cod e/vendor/utopia-php/framework/src/App.php on line 593 appwrite | [Error] File: /usr/src/code/app/controllers/api/storage.php appwrite | [Error] Line: 360

@theMeysam
Copy link
Author

Screenshot_20220604_163003

@stnguyen90
Copy link
Contributor

It looks your sending "data" string for the file rather than sending the actual file. Maybe this will give you some insight into sending file data: https://community.n8n.io/t/trying-to-upload-a-file-to-an-http-endpoint/4459/2

Otherwise, things look fine on the Appwrite side.

@theMeysam
Copy link
Author

Thanks your comment I could set data for file (I think).
The problem now is that appwrite server need "fileId" and I don't know how to send it to my appwrite server. :-(
Screenshot_20220605_121322

@stnguyen90
Copy link
Contributor

Screenshot_20220604_163003

Do you still have the fileId body parameter and headers?

@theMeysam
Copy link
Author

Screenshot_20220604_163003

Do you still have the fileId body parameter and headers?

Yes, I have header properties that I cut from mentioned screenshot.
In http request node (on n8n) when I set "send binary data" true, there isn't any options to add another field that I add (for example) "fileId" value. :-(

@stnguyen90
Copy link
Contributor

Ah sounds like it's unsupported by n8n.

Someone did create an Appwrite package for n8n but it doesn't look like it supports file uploads yet. Perhaps you can submit a feature request.

@Meldiron
Copy link
Contributor
Meldiron commented Jun 15, 2022

Hey there 👋

As @stnguyen90 suggested, this is not natively supported by n8n. But there is a way! 😎

We can use Functions node to do this:

CleanShot 2022-06-15 at 13 53 37

In there, we will need to use request-promise-native so make sure to install that on your n8n device (sudo npm install -g request-promise-native) and specify it in the environment variables definition:

NODE_FUNCTION_ALLOW_EXTERNAL=request-promise-native

Whith that ready, enter following code into your function node:

const request = require('request-promise-native');

const binaryData = items[0].binary.data;

try {

  const data = await request({
  uri: "[YOUR_ENDPOINT]/v1/storage/buckets/[YOUR_BUCKET_ID]/files",
  method: "POST",
  headers: {
    'content-type': 'multipart/form-data',
    'x-appwrite-key': '[YOUR_API_KEY]',
    'x-appwrite-project': '[YOUR_PROJECT_ID]'
  },
  formData: {
    file: {
      value: Buffer.from(binaryData.data, 'base64'),
      options: {
        filename: binaryData.fileName,
        contentType: binaryData.mimeType,
      },
     },
     fileId: 'unique()'
  },
});
 
} catch(err) {
  return {ok: false, err: err};
}

return {ok:true};

Make sure to enter your endpoint, project ID, bucket ID and API key in the code example.

With that, make sure you have a file defined before this node (in my case it was defined by another HTTP request node that was fetching file from an URL), and you are ready to execute the workflow.

In the end, you should see a successful execution and a file uploaded to your Appwrite Bucket:

CleanShot 2022-06-15 at 13 57 30

CleanShot 2022-06-15 at 13 52 56

I am attaching the whole workflow as a file. If you use it, make sure to replace all XXXXX... placeholders with your information.

appwrite-storage-workflow.json.zip

@Meldiron Meldiron self-assigned this Jun 15, 2022
@Meldiron Meldiron changed the title 🐛 Bug Report: Get 500 error when create file with API 🐛 Bug Report: Can't createFile via n8n flow Jun 17, 2022
@stnguyen90
Copy link
Contributor

@theMeysam have you had a chance to test @Meldiron's suggestion? Is there anything else you need or can this be closed?

@stnguyen90
Copy link
Contributor

Closing as no further action required.

@stnguyen90 stnguyen90 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2022
@theMeysam
Copy link
Author

Thank you @Meldiron
It work as a charm for me.
Best regards;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
0