supabase / storage

S3 compatible object storage service that stores metadata in Postgres
https://supabase.com/docs/guides/storage
Apache License 2.0
811 stars 115 forks source link

Wrong URL generated for resumable upload in storage API for local development #339

Closed dishwad closed 1 year ago

dishwad commented 1 year ago

Bug report

Describe the bug

Resumable uploads aren't working during local development because the wrong URL is being generated.

To Reproduce

Javascript code snippet from Discord thread

Python code snippet:

from typing import BinaryIO

from tusclient import client

from app.core.config import settings
from app.schemas.token import TokenData

# Must be set to 6MB (for now) according to Supabase's limitations.
DEFAULT_CHUNK_SIZE: int = 6 * 1024 * 1024

def upload_file_to_bucket(
    user_token_data: TokenData, file_name: str, file: BinaryIO, content_type: str = "application/pdf"
):
    endpoint = f"{settings.SUPABASE_URL}/storage/v1/upload/resumable"
    headers = {
        "Authorization": f"Bearer {user_token_data.access_token}",
        "X-Upsert": "true",
    }
    metadata = {
        "bucketName": settings.SUPABASE_DOCUMENT_FILES_BUCKET_NAME,
        "objectName": f"{user_token_data.user_id}/{file_name}",
        "contentType": content_type,
        "cacheControl": "3600",
    }

    tus_client = client.TusClient(endpoint, headers=headers)
    uploader = tus_client.uploader(file_stream=file, metadata=metadata, chunk_size=DEFAULT_CHUNK_SIZE)
    uploader.upload()

This exception is generated when the upload_file_to_bucket function runs:

tusclient.exceptions.TusUploadFailed: HTTPConnectionPool(host='localhost', port=80): Max retries exceeded with url: /upload/resumable/ZG9jdW1lbnQtZmlsZXMvYTc0ZGVlZTAtNThhNS00M2QwLTliNzYtODRjYjZkN2MyMDNjL0Jhc2ljLU5vbi1EaXNjbG9zdXJlLUFncmVlbWVudC5wZGYvZjYyNGJiNmYtZWM5YS00MWExLWI4M2QtMDVkMDgxNDI0ZDhl (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x1703e61c0>: Failed to establish a new connection: [Errno 61] Connection refused'))

Expected behavior

Should generate http://localhost/storage/v1/upload instead of http://localhost/upload.

Screenshots

Screenshot in Discord thread.

System information

inian commented 1 year ago

Hi Alex,

Thank you for reporting this issue.

It was just fixed in the beta version of the CLI.

It should reach our mainline on June 13th.

glib-0 commented 4 months ago

I'm still getting this issue with self-hosted Supabase. The first chunk uploads fine, but then subsequent PATCH/HEAD requests are using http://localhost/upload/resumable/[fingerprint] as the uploadUrl - the same value is stored in localStorage. If I change the uploadUrl (in localStorage) to http://localhost:8000/stoarge/v1/upload/resumable/[fingerprint] then it manages to complete.