Skip to content

Instantly share code, notes, and snippets.

@adrianhorning08
Last active September 22, 2025 18:46
Show Gist options
  • Select an option

  • Save adrianhorning08/585300125e6fa38f1603f16d71d6338d to your computer and use it in GitHub Desktop.

Select an option

Save adrianhorning08/585300125e6fa38f1603f16d71d6338d to your computer and use it in GitHub Desktop.

Revisions

  1. adrianhorning08 revised this gist Sep 22, 2025. 1 changed file with 18 additions and 18 deletions.
    36 changes: 18 additions & 18 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -1,25 +1,25 @@
    import axios from "axios";
    import { createClient } from "@supabase/supabase-js";
    import fs from 'fs';
    import { createClient } from '@supabase/supabase-js';

    const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);
    const SUPABASE_URL = process.env.SUPABASE_URL;
    const SUPABASE_KEY = process.env.SUPABASE_KEY;
    const supabase = createClient(SUPABASE_URL, SUPABASE_KEY);

    const url = "https://example.com/image.jpg"; // change this
    const bucket = "images"; // your bucket name
    const path = `uploads/${Date.now()}.jpg`; // path in bucket
    const filePath = 'video.mp4';
    const bucket = 'videos'; // change to your bucket
    const storagePath = `uploads/${filePath}`;

    // download as buffer
    const response = await axios.get(url, { responseType: "arraybuffer" });
    const buffer = Buffer.from(response.data);
    const fileBuffer = fs.readFileSync(filePath);

    // upload to supabase
    const { data, error } = await supabase.storage
    const { error } = await supabase.storage
    .from(bucket)
    .upload(path, buffer, {
    contentType: response.headers["content-type"],
    .upload(storagePath, fileBuffer, {
    contentType: 'video/mp4',
    upsert: true
    });

    if (error) {
    console.error(error);
    } else {
    console.log("Uploaded:", data);
    }
    if (error) throw error;

    fs.unlinkSync(filePath); // delete local file

    console.log('Uploaded and deleted local copy.');
  2. adrianhorning08 created this gist Sep 22, 2025.
    25 changes: 25 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    import axios from "axios";
    import { createClient } from "@supabase/supabase-js";

    const supabase = createClient(process.env.SUPABASE_URL, process.env.SUPABASE_KEY);

    const url = "https://example.com/image.jpg"; // change this
    const bucket = "images"; // your bucket name
    const path = `uploads/${Date.now()}.jpg`; // path in bucket

    // download as buffer
    const response = await axios.get(url, { responseType: "arraybuffer" });
    const buffer = Buffer.from(response.data);

    // upload to supabase
    const { data, error } = await supabase.storage
    .from(bucket)
    .upload(path, buffer, {
    contentType: response.headers["content-type"],
    });

    if (error) {
    console.error(error);
    } else {
    console.log("Uploaded:", data);
    }