Last active
November 7, 2025 02:31
-
-
Save jstoone/a377fb3b171240ea4906b92e34bf1d21 to your computer and use it in GitHub Desktop.
Supabase: Resumable uploads RLS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const handleFileUploadTUS = async (formData: FormData) => { | |
| const origFile = formData.get("audio") as File; | |
| const file = new File([origFile], encodeURIComponent(origFile.name), { | |
| type: origFile.type, | |
| }); | |
| const { | |
| data: { session }, | |
| } = await supabase.auth.getSession(); | |
| if (!session?.access_token) { | |
| console.error("NO ACCESS TOKEN"); | |
| throw new Error("No access token"); | |
| } | |
| // This succeeds | |
| supabase.storage | |
| .from("tapes") | |
| .upload(`${user?.id}/${secureId()}/raw`, file, {}); | |
| // This fails RLS | |
| uploadViaTus({ | |
| file, | |
| bucketName: "tapes", | |
| fileName: `${user?.id}/${secureId()}/raw`, | |
| acceessToken: session?.access_token, | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import * as tus from "tus-js-client"; | |
| export const uploadViaTus = async ({ | |
| acceessToken, | |
| bucketName, | |
| fileName, | |
| file, | |
| }: { | |
| acceessToken: string; | |
| bucketName: string; | |
| fileName: string; | |
| file: File; | |
| }) => { | |
| return new Promise(async (resolve, reject) => { | |
| var upload = new tus.Upload(file, { | |
| endpoint: `${window.WINDOW_ENV.SUPABASE_URL}/storage/v1/upload/resumable`, | |
| retryDelays: [0, 3000, 5000, 10000, 20000], | |
| headers: { | |
| apikey: `${window.WINDOW_ENV.SUPABASE_ANON_KEY}`, | |
| authorization: `Bearer ${acceessToken}`, | |
| "x-upsert": "true", // optionally set upsert to true to overwrite existing files | |
| }, | |
| uploadDataDuringCreation: true, | |
| removeFingerprintOnSuccess: true, // Important if you want to allow re-uploading the same file https://github.com/tus/tus-js-client/blob/main/docs/api.md#removefingerprintonsuccess | |
| metadata: { | |
| bucketName: bucketName, | |
| objectName: fileName, | |
| contentType: file.type, | |
| cacheControl: "3600", | |
| }, | |
| chunkSize: 6 * 1024 * 1024, // NOTE: it must be set to 6MB (for now) do not change it | |
| onError: function (error) { | |
| console.log("Failed because: " + error); | |
| reject(error); | |
| }, | |
| onProgress: function (bytesUploaded, bytesTotal) { | |
| var percentage = ((bytesUploaded / bytesTotal) * 100).toFixed(2); | |
| console.log(bytesUploaded, bytesTotal, percentage + "%"); | |
| }, | |
| onSuccess: function () { | |
| console.log(upload); | |
| console.log("Download %s from %s", file.name, upload.url); | |
| resolve(file); | |
| }, | |
| }); | |
| // Check if there are any previous uploads to continue. | |
| return upload.findPreviousUploads().then(function (previousUploads) { | |
| // Found previous uploads so we select the first one. | |
| if (previousUploads.length) { | |
| upload.resumeFromPreviousUpload(previousUploads[0]); | |
| } | |
| // Start the upload | |
| upload.start(); | |
| }); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
--// CrisRussel Hub by ChatGPT
--// UI moderno y movible + funciones básicas (solo para uso en tu propio juego)
-- Crear ScreenGui
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "CrisRusselHub"
ScreenGui.ResetOnSpawn = false
ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
-- Crear Frame principal (Hub)
local Frame = Instance.new("Frame")
Frame.Name = "MainFrame"
Frame.Size = UDim2.new(0, 200, 0, 150)
Frame.Position = UDim2.new(0.3, 0, 0.3, 0)
Frame.BackgroundTransparency = 0.3
Frame.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
Frame.Active = true
Frame.Draggable = true
Frame.Parent = ScreenGui
-- Título
local Title = Instance.new("TextLabel")
Title.Text = "CrisRussel"
Title.Size = UDim2.new(1, 0, 0, 30)
Title.BackgroundTransparency = 1
Title.TextColor3 = Color3.fromRGB(0, 255, 255)
Title.Font = Enum.Font.GothamBold
Title.TextSize = 20
Title.Parent = Frame
-- Función para crear botones
local function createButton(name, yPos)
local btn = Instance.new("TextButton")
btn.Text = name
btn.Size = UDim2.new(1, -20, 0, 25)
btn.Position = UDim2.new(0, 10, 0, yPos)
btn.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
btn.TextColor3 = Color3.fromRGB(255, 255, 255)
btn.Font = Enum.Font.Gotham
btn.TextSize = 16
btn.Parent = Frame
return btn
end
-- Crear botones
local btnTP = createButton("TP (Guardar)", 40)
local btnTP2 = createButton("TP2 (Ir)", 70)
local btnTras = createButton("Traspasar", 100)
local btnFly = createButton("Volar", 130)
-- Variables de funciones
local savedPos = nil
local flying = false
local noclip = false
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("HumanoidRootPart")
-- Guardar ubicación
btnTP.MouseButton1Click:Connect(function()
savedPos = hum.Position
btnTP.Text = "Ubicación Guardada!"
wait(1)
btnTP.Text = "TP (Guardar)"
end)
-- Teletransportar
btnTP2.MouseButton1Click:Connect(function()
if savedPos then
hum.CFrame = CFrame.new(savedPos)
end
end)
-- Traspasar paredes (noclip)
btnTras.MouseButton1Click:Connect(function()
noclip = not noclip
btnTras.Text = noclip and "Traspasar: ON" or "Traspasar: OFF"
game:GetService("RunService").Stepped:Connect(function()
if noclip and char then
for _, v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") then
v.CanCollide = false
end
end
end
end)
end)
-- Volar
btnFly.MouseButton1Click:Connect(function()
flying = not flying
btnFly.Text = flying and "Volar: ON" or "Volar: OFF"
local UIS = game:GetService("UserInputService")
local speed = 50
end)