API File Upload Action - NodeJS & PHP [Open Source]

I don’t quite remember why I don’t have the filepath key set there, but I assume it could have been because the path was remote, I did not add it. Or because this value is optional.

It could be that either your remote file or the one I tested with, has some issue… in anycase, having the extra param does not hurt, so will add it to the repo. :slight_smile:

Glad to see you got it work finally, and probably learned enough to create your own extensions. :sweat_smile:

1 Like

Awesome. Thanks for adding it.

And yeah I’ve made some simple extensions, still need to learn more about async and promises though!

One last thing. With the regular ‘api action’ you can set the data type to JSON and then pass your own JSON with data bindings:

This doesn’t happen in your extension. I’m guessing it’s due to wappler limitations, but I haven’t worked with extensions enough to know for sure. Do you know if it’s possible to get this in the UI?

From what I remember, it is possible. Its just a text area input. Will have to test it out though for the JSON formatting thing.

Is there a HJSON option to do this?: if data type = ‘json’, show text field.
If data type = ‘auto’, show grid field

Yes. Refer the drop down for files and data.

1 Like

What’s your version of node-fetch and form-data? I got this error on latest versions:

require() of ES Module /opt/node_app/node_modules/node-fetch/src/index.js from /opt/node_app/extensions/server_connect/modules/FileUploadModule.js not supported.\nInstead change the require of index.js in /opt/node_app/extensions/server_connect/modules/FileUploadModule.js to a dynamic import() which is available in all CommonJS modules.

Edit: Fixed by downgrading node-fetch:
npm install node-fetch@2 --save

1 Like

Yes. Someone posted this question earlier as well. Maybe here or some other post.

There’s also a bug with node-fetch, the multipart/form-data boundary is not sent in the headers, so this can cause some requests to fail with a 500 Internal Server Error or similar.

Patch, intentionally delete the Content-Type header so it can be filled automatically:

    delete headersObj['Content-Type'];
    // Call API
    let response = null, responseError = null;
    response = await fetch(options.APIURL, {
        method: 'POST',
        headers: { ...headersObj },
        body: bodyData
// ...

I’m running the server action where I put this extension in, in the browser.

The extension returns this: "image
and this in the devtools image

I’m getting ‘retry later’ because I’m rate limited.

I think they probably give me more information (so I know where to continue off) but not sure if I’m missing it because they don’t send it… OR that the extension doesn’t pass this back.

I’m guessing the latter.

How can I edit the extension so it passes all the info it gets from the endpoint?

You can’t edit the extension if you don’t know how exactly they’re returning the additional information

However, such information is usually passed by response headers, so in your response you want to include (copy) some of the response headers from the request

You may only want to copy the response headers that are not already present in your response object, so you don’t overwrite important ones, e.g.: “Host

1 Like

If you look at the code towards the end, you will see that the extension is returning the complete response object as is - success or failure. Which is probably why you are seeing the correct status code of 429.
Best to run the API on Postman to see the returned response.

Having dealt with 429s before, I think “Retry later” is the only response body that you are getting, along with 429 status code. Or there could be something in the headers as Apple suggests.

1 Like

hey @sid,
thanks for that extension!

how can i send raw data to the body?
in the normal API Action i have a textfield where i can add a json and bind it to some datas.

Can you tell me how i can send that json with you extension?

This was requested sometime ago as well. Unfortunately, I am not sure when I will be able to do this.
For now, you will have to get into HJSON and JS if you want the input textarea field.
If your API provider supports it, you can set the key-value pairs in API DETAILS > Input Data section, instead of a JSON object.

Hi @sid.

The API upload looks good.

Are there any plans to make this available for ASP?

Thanks,
Ray

Hi Ray.
ASP .NET in Wappler does not support custom extensions.
ASP Classic in Wappler does support it, but I have no experience with that.

@sid thanks for creating this, it’s saved my bacon, just as I’m sure it has saved it for many other people!

We could really do with this capability being integrated into Wappler.

1 Like

@sid How do we go about installing this?
I’ve tried to add the gitlab repo in the extensions section of the Project Options but the API File upload Action is not showing up.

Hello @astroGlide

Please see:

You will have to do a manual installation, as explained in the help docs.
Links in the main post… and also shared above by franse.

Just tried all of that and it still is not showing up in the Server Connect. The extension was added manually.
image
image