-1

I am interested to download an image from an URL for instance "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQo2zi7aWGrKd8eTtROEbeG4noyYyEicLaqpMOmqXXN&s%22" and then pass it to something like a s3 bucket. Previously I have tried to fetch it, make a blob object, and then create a URL for it. But that dint seem to work. Here is the code of what I have done so far and it ends up creating an URL however it does not pass through the supabase client

      console.log(await req);
      const imgBlob = await req.blob();
      const imgUrl = URL.createObjectURL(imgBlob);
      const Imagefile = new File([imgUrl],"imageGenerator.png",{type:"image/png"});
      const d = new Date();
      const time = d.getTime();
      console.log(imgBlob);
      console.log(Imagefile);
      const {data,error} = await supabase.storage.from('ama').upload(`${time}`,Imagefile,{cacheControl:'3600',upsert: false})``` 
.

1 Answers1

0

You should be just able to upload an blob like this:

const imgBlob = await req.blob();
const d = new Date();
const time = d.getTime();
const {data,error} = await supabase.storage.from('ama').upload(`${time}`,imgBlob,{cacheControl:'3600',upsert: false})

dshukertjr
  • 15,244
  • 11
  • 57
  • 94
  • 1
    Thanks However I went with an alternative approach, I converted the Image URL to image in byteArray format and then pushed it to the blob – kaushik choudhury Mar 14 '23 at 08:36