#Need some help in setting up Supabase storage API endpoint

1 messages · Page 1 of 1 (latest)

stone stump
#

I keep getting this error about the route not being found but the bucket exists. I am not sure where I am making a mistake. I can share more info if it is required.

midnight coralBOT
#

Hi There!
Thanks for reaching out to us. One of our engineers will be with you shortly.

If you are stuck with an issue/error, please help us with following information.

  1. Which version of Appsmith are you on?
  2. Provide screenshots/screen recordings of the original error/code snippet.
  3. Add details about your use case and provide steps to reproduce the issue, if
    possible.
stone stump
#
  1. I am on the latest cloud version
  2. Screenshot is already attached
  3. I am not able to figure out the exact correct way of setting up the REST API endpoint for Supabase Storage. I have attached a screenshot of my current approach.
wooden crest
#

Hi @stone stump, I'm here to help you. Could you please tell me which database your API uses?

stone stump
#

i.e. Postgres

#

But here I am only setting up the storage

wooden crest
#

Perfect thanks, I will reproduce this problem in my local environment to be able to help you appropriately. 😃

stone stump
wooden crest
#

Thanks a lot!

wooden crest
#

Hello @stone stump , could you please share the complete error message in the previous capture, it is cut off.

stone stump
wooden crest
#

Thanks

#

Could you press the debug button and show me that information?

stone stump
#

Weirdly, I am getting a different error now.

wooden crest
#

I see that.

stone stump
#

That wasnt the error a couple hours back.

wooden crest
#

Could you increase the waiting time?

stone stump
#

Okay

wooden crest
stone stump
#

Changed it to 20s and I am still getting the same thing.

wooden crest
#

we could try with 50s

stone stump
#

Trying now

wooden crest
#

Perfect!

stone stump
#

Still getting the same error but with 50k ms

wooden crest
#

Thank you, I will continue to investigate this in my local environment to give you an answer.

stone stump
#

Okay

wooden crest
#

Could you please show me the configuration of your API?

stone stump
#

Which part do you need to see?

#

Headers

wooden crest
#

the configuration of your data source.

stone stump
#

Data source

wooden crest
#

Thanks!!

stone stump
wooden crest
#

Thank you, I managed to replicate your problem. I am investigating the cause of it. The documents that you send me are very helpful!

stone stump
#

Okay. I might be offline for the next several hours as it is pretty late for me. If you need anything else, do let me know. I will reply in the morning. And hopefully you would have found the cause by then as well.

wooden crest
#

Perfect, good night.

wooden crest
#

Hello @stone stump, I have a solution for your problem, I share a video to show you the correct configuration to generate this query.
Please tell me if this worked for you 😃

#

Let me provide you with the URL.

/object/<<yourbucketname>>/{{FilePicker1.files[0].name}}

stone stump
#

I will try this in the morning now but I suppose that if it works for you, it will work for me too.

The only difference I see is the use of object in the url and having the key three times in the data source which is especially weird.

wooden crest
stone stump
#

Oh yeah this too

wooden crest
#

I show you how I found out

stone stump
#

Yeah I suppose. I'll give it a try tomorrow morning.

wooden crest
#

I will be attentive to see if it worked, is it is not the case I will be happy to help you.

stone stump
#

That's such a clever way of reverse engineering the url. Thanks for the help. I'll try it and let you know if I have any issues or not.

wooden crest
#

Thanks!

stone stump
#

@wooden crest I am getting this error. As far as I know, I should not have to provide the JWT token when I am already providing the API key.

wooden crest
#

Hi @stone stump, Could you show me the configuration of the data source, please?

stone stump
#

I have the same apiKey as the Bearer token as well

wooden crest
#

Could you show me all the settings like you did yesterday? please

wooden crest
#

Yes

stone stump
#

The name of the file shouldn't matter by the way.

#

I get the same response with {{FilePicker.files[0].name}} anyway

wooden crest
#

Could you show me a screenshot of your Supabase panel like this, please?

stone stump
wooden crest
#

Could you put this URL.

/object/workflow-files/qwerty.csv

stone stump
#

where?

wooden crest
stone stump
wooden crest
#

Ok, look, let's do a test, can you help me?

stone stump
#

Sure

wooden crest
#

I will pass you the credentials of this instance that I create from supbase.

#

/object/appsmithfiles/{{FilePicker1.files[0].name}}

stone stump
#

Okay

wooden crest
#

A moment before doing the tests, you could put apikey first and then authorization

stone stump
#

Okay

wooden crest
#

Before saving the data source you must rewrite the bearer token.

stone stump
#

What is your apiKey?

wooden crest
#

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9ic3FtcGNmdHh1bnJsdWdsdnpmIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzAyNzAyNzcsImV4cCI6MTk4NTg0NjI3N30.AQYCpMvA4syM_cmOWK8coTlfnnS0jtuC_4uIw34uoZs

stone stump
#

This is with your URL, your api key as apiKey and your api key as Bearer Token in the data source.

#

This is after using your api key as authorization as well in the data source header

wooden crest
stone stump
#

Ignore the last one. I forgot to reenter the bearer token

stone stump
#

Added. The app is called Workflow tracker

wooden crest
#

@stone stump , could you please send me your key and your URL? It can be private.

stone stump
#

Okay

wooden crest
stone stump
#

Done

wooden crest
#

Could you load a file from the dashboard and show me the network like in this image please.

#

Could you share the JWT token privately?

stone stump
#

@wooden crest Any luck?

wooden crest
#

I find myself investigating.

stone stump
#

Okay. Let me know if you need anything else?

wooden crest
#

Perfect

#

Could you copy this and send it to me please?

stone stump
#

isnt it the same as the apiKey I sent?

wooden crest
#

Don't, compare them and they look different.

stone stump
#

Yeah I just noticed

#

That is weird

#

btw, sent it thru DM

wooden crest
stone stump
#

I checked it just now

#

The api key that I am using in appsmith is the anon public key

#

The one that appears in the browser inspector is service_role secret

wooden crest
#

It works now you can try it, the problem was the token. I think the supabase platform bugged you.

wooden crest
#

Could you confirm that this already works for you?

stone stump
#

Yes I just checked. It is working now.

One other question: In the supabase dashboard, it says that the file type is application/json. Would that not affect me if I want to query ALL pdfs or pngs or whateever?

wooden crest
#

No, in general, this does not affect or should not affect, you could upload a couple of files for you to check

stone stump
#

I just did. All get uploaded with the type application/json

wooden crest
#

Perfect!

#

I'm glad I was able to help you with this issue, have a great week.

#

@stone stump Could you please delete the screenshots where your keys appear

stone stump
#

Done. Also, share the exact set of settings that you used to set up the connection to Supabase storage so that future users can reference this convo.

wooden crest
#

That's a great idea, I'm going to do it!

wooden crest
young wind
#

Hi!

#

I found all this specially helpful, but I need to upload to supabase storage a photo taken from the Camera Widget of appsmith, and I'm not being able to do it

#

The camera widget provides an imageBlobURL, (which can't be fetched since fetch is not allowed in JS methods), and imageDataURL, imageRawBinary, which I think are also not profitable. Any ideas on how to make this work? @wooden crest

midnight coralBOT
#

Have you tired passing the blob to the API? I think when we pass blobs to
queries we turn them into base64.

young wind
#

I have, but I get an error

midnight coralBOT
#

can you send a screenshot?

young wind
#

it's a get request

midnight coralBOT
#

I meant as a param in the supabase insert query

young wind
#

You mean in the Supabase Storage API query?

#

In case you mean this url, could you please give me an example of what kind of param should I use to pass the blob url?

midnight coralBOT
#

It seems like you would pass the blob url as the path

young wind
#

I don't really think that will work 😅 have you tried it?

midnight coralBOT
#

@young wind, We discussed this internally. We are already building a
sample app for your use case. We might need a couple of hours but you'll have a
resolution.
Thanks for your patience!

young wind
#

Nice, thank you so much! Let me know please 🙂

young wind
#

Hi! How is the sample app going? May I help you with anything?

midnight coralBOT
#

Hello there. Thank you for your patience.

I have investigated this and came up with a solution for you

#

Hello there. Thank you for your patience.

I have investigated this and came up with a solution for you

young wind
#

Nice!

midnight coralBOT
#

To be able to upload images directly from the camera, you'll need to use the
name of the image as the last part of your url and in the json body, use the
information as shown in the screenshot as well.

#

To be able to upload images directly from the camera, you'll need to use the
name of the image as the last part of your url and in the json body, use the
information as shown in the screenshot as well.

young wind
#

Iteresting!

midnight coralBOT
#

If you want to be able to send image directly from the camera widget, specify a
custom name for the image in the last part of the url (this is the name you'll
see on your supabase bucket) and then use the JSON body as shown in the
screenshot as well

young wind
#

Hi

#

Thanks for going though the issue. I have just tried it and it doesn't work for me, I might be missing something, but since we are sending a json body, automatically the content-type header is set to application/json, and when this request is sent, what you get in the supabase storage bucket is not an image, but a json. If I download the file from the bucket, and change the extension to .webp, it just gives a white square. Any ideas?

midnight coralBOT
#

Sorry about the issue. I didn't try to open the image after uploading it so,
sorry for that.
I'll look at this issue now and see if I can come up with anything.

If i'm not able to come up with anything, I'll send this back to our tech team
to help you with it but I'll try everything I can to get this issue resolved for
you today.

#

Sorry about the issue. I didn't try to open the image after uploading it so,
sorry for that.
I'll look at this issue now and see if I can come up with anything.

If i'm not able to come up with anything, I'll send this back to our tech team
to help you with it but I'll try everything I can to get this issue resolved for
you today.

young wind
#

No worries thanks!

young wind
#

My solution has passed by creating a supabase edge function where I send the bucket, the path and the image in base64, so the function converts the base64 data into a blob and adds it to the bucket and path via supabase-js client, and returns the response

#

import { serve } from "https://deno.land/[email protected]/http/server.ts";
import { createClient } from "https://esm.sh/@supabase/[email protected]";

serve(async (req) => {
try {
const supabaseClient = createClient(
Deno.env.get("SUPABASE_URL") ?? "",
Deno.env.get("SUPABASE_ANON_KEY") ?? ""
);

    const { bucket, path, base64 } = (await req.json()) as {
        bucket: string;
        path: string;
        base64: string;
    };
    const imageBlob = await fetch(base64).then((res) => res.blob());
    imageBlob.type;
    const { data, error } = await supabaseClient.storage
        .from(bucket)
        .upload(path, imageBlob, {
            contentType: imageBlob.type,
        });
    if (error) throw error;

    return new Response(JSON.stringify(data), {
        headers: { "Content-Type": "application/json" },
        status: 200,
    });
} catch (error) {
    return new Response(JSON.stringify({ error: error.message }), {
        headers: { "Content-Type": "application/json" },
        status: 400,
    });
}

});

midnight coralBOT
#

Hi there.
Does this solution work perfectly for your previously reported issue on your
appsmith app?

young wind
#

Yes, though it means creating another repo for the function, deploying it, etc, which is a bit of a pain

#

It would be super cool if we could upload it just through the rest api

young wind
#

Hi! I showed my product to the client and said the photo upload was too slow...

#

The process of having to call the supabase function in order to upload the file instead of just calling the supabase storage REST API slows it down

#

And also, I finally had to use the file picker widget in order to get the base64 representation of the image, since the camera widget didn't provide me of the photo content, neither in binary nor in base64...