View contents of an uploaded file

I’m trying to create a plugin that opens a file uploaded on the app.
I’m creating an actions plugin, so the user can use any existing file uploader, use the URL, then open it using node’s request. I can’t make it return the resulting body.
Does anyone know what to do here?

Solved it. Tried a different approach using Elements.

Hi @lois.laput,

What was the approach you took with Elements?

I opted to use Exposed States and Events of Elements. The value of exposed states would only be reliable when the event is triggered.

1 Like

I actually used your code and an answer by @serg.sargsyan and was able to make it work. Here’s how I did it:

function(properties, context) {
    var input;
    var url = "https:" + properties.filename;
    
    response = context.request(url);
    json = response.body;
    input = JSON.stringify(json, null, 3)
    return {contents: input};
}

You might not need to use JSON.stringify.

This worked in the actions server-side?
I’ll try this out! :slight_smile: thanks!

Yes, this is the code for a server-side action