#Need some help in setting up Supabase storage API endpoint
1 messages · Page 1 of 1 (latest)
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.
- Which version of Appsmith are you on?
- Provide screenshots/screen recordings of the original error/code snippet.
- Add details about your use case and provide steps to reproduce the issue, if
possible.
- I am on the latest cloud version
- Screenshot is already attached
- 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.
Hi @stone stump, I'm here to help you. Could you please tell me which database your API uses?
Supabase
i.e. Postgres
But here I am only setting up the storage
Perfect thanks, I will reproduce this problem in my local environment to be able to help you appropriately. 😃
No problem. This is the only documentation that I have found. Might help you in setting it up.https://supabase.github.io/storage-api/#/
Thanks a lot!
Hello @stone stump , could you please share the complete error message in the previous capture, it is cut off.
I see that.
That wasnt the error a couple hours back.
Could you increase the waiting time?
Okay
Changed it to 20s and I am still getting the same thing.
we could try with 50s
Trying now
Perfect!
Still getting the same error but with 50k ms
Thank you, I will continue to investigate this in my local environment to give you an answer.
Okay
Could you please show me the configuration of your API?
the configuration of your data source.
Thanks!!
@wooden crest This might help as well: https://imknight.com/upload-files-to-supabase-storage-using-retool
Thank you, I managed to replicate your problem. I am investigating the cause of it. The documents that you send me are very helpful!
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.
Perfect, good night.
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}}
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.
Oh yeah this too
If something strange but it is what supabase needs.
I show you how I found out
Yeah I suppose. I'll give it a try tomorrow morning.
I will be attentive to see if it worked, is it is not the case I will be happy to help you.
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.
Thanks!
@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.
Hi @stone stump, Could you show me the configuration of the data source, please?
I have the same apiKey as the Bearer token as well
Could you show me all the settings like you did yesterday? please
Of the POST api?
Yes
The name of the file shouldn't matter by the way.
I get the same response with {{FilePicker.files[0].name}} anyway
Could you put this URL.
/object/workflow-files/qwerty.csv
where?
Oh I tried that initially. then I tried making a public bucket called test and it didnt work with that as well.
Ok, look, let's do a test, can you help me?
Sure
I will pass you the credentials of this instance that I create from supbase.
/object/appsmithfiles/{{FilePicker1.files[0].name}}
Okay
A moment before doing the tests, you could put apikey first and then authorization
Okay
Before saving the data source you must rewrite the bearer token.
What is your apiKey?
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im9ic3FtcGNmdHh1bnJsdWdsdnpmIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NzAyNzAyNzcsImV4cCI6MTk4NTg0NjI3N30.AQYCpMvA4syM_cmOWK8coTlfnnS0jtuC_4uIw34uoZs
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
Could you add [email protected] to your workspace? In order to review this better.
Okay sure
Added. The app is called Workflow tracker
@stone stump , could you please send me your key and your URL? It can be private.
Okay
Done
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?
@wooden crest Any luck?
I find myself investigating.
Okay. Let me know if you need anything else?
isnt it the same as the apiKey I sent?
Don't, compare them and they look different.
Yes
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
It works now you can try it, the problem was the token. I think the supabase platform bugged you.
If that is the one that is necessary to include in the authentication and in the header.
Could you confirm that this already works for you?
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?
No, in general, this does not affect or should not affect, you could upload a couple of files for you to check
I just did. All get uploaded with the type application/json
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
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.
That's a great idea, I'm going to do it!
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
Have you tired passing the blob to the API? I think when we pass blobs to
queries we turn them into base64.
I have, but I get an error
can you send a screenshot?
I meant as a param in the supabase insert query
You mean in the Supabase Storage API query?
The one with this url: supabaseproject.supabase.co/storage/v1/object/bucketName/path
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?
It seems like you would pass the blob url as the path
I don't really think that will work 😅 have you tried it?
@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!
Nice, thank you so much! Let me know please 🙂
Hi! How is the sample app going? May I help you with anything?
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
Nice!
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.
Iteresting!
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
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?
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.
No worries thanks!
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,
});
}
});
Hi there.
Does this solution work perfectly for your previously reported issue on your
appsmith app?
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
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...