Skip to content

The supabase storage api does not parse the RANGE http header #322

@xyjixyjixyji

Description

@xyjixyjixyji

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Supabase supports RESTful API to access its storage.

For upper layer applications, which require range read for inner bytes, they typically attach a RANGE header in the GET request for the object in supabase storage.

However, currently the supabase storage API does not parse the RANGE header, working as if the RANGE header is not attached.

We found out that although this uses the RANGE header, but the inside of it does not.

getAsset(request: FastifyRequest, options: RenderOptions) {
    return this.backend.getObject(options.bucket, options.key, options.version, {
      ifModifiedSince: request.headers['if-modified-since'],
      ifNoneMatch: request.headers['if-none-match'],
      range: request.headers.range,
    })
  }
  async getObject(
    bucketName: string,
    key: string,
    version: string | undefined
  ): Promise<ObjectResponse> {
    const file = path.resolve(this.filePath, withOptionalVersion(`${bucketName}/${key}`, version))
    const body = fs.createReadStream(file)
    const data = await fs.stat(file)
    const { cacheControl, contentType } = await this.getFileMetadata(file)
    const lastModified = new Date(0)
    lastModified.setUTCMilliseconds(data.mtimeMs)

    const checksum = await fileChecksum(file)

    return {
      metadata: {
        cacheControl: cacheControl || 'no-cache',
        mimetype: contentType || 'application/octet-stream',
        lastModified: lastModified,
        // contentRange: data.ContentRange, @todo: support range requests
        httpStatusCode: 200,
        size: data.size,
        eTag: checksum,
        contentLength: data.size,
      },
      body,
    }
  }

To Reproduce

Previous discussion on this issue is here.

To reproduce this, you can simply read an object from supabase with RANGE header, and the RANGE header will not work as expected.

Expected behavior

The supabase storage API should parse the RANGE header and hence support range read.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions