Giter Club home page Giter Club logo

Comments (4)

Klowner avatar Klowner commented on July 17, 2024

Listing storage-r2 files is a little tricky since files are stored as individual chunks in separate R2 records and reassembled by the R2File (which can be obtained through storage.getFile(location) (R2 multipart upload didn't yet exist when storage-r2 was written).

Ideally, during "before-create" or "after-complete" hooks, you would store the location of the uploaded file elsewhere (either in KV or some external service) for later retrieval by their individual locations.

But if you really want to list them from R2, you'll need to use the R2 workers API directly. The downside is that (as previously mentioned), the individual chunks are stored in consecutively numbered files.

location R2 record paths
my/images/cat.png my/images/cat.png/0000000000
my/images/cat.png/0000000001
my/images/cat.png/0000000002

So, if you filter list results to look for any paths ending with 10 zeroes, then stripping the trailing "/0000000000" will give you a location that you can pass to storage.getFile().

from tussle.

BLEE0408 avatar BLEE0408 commented on July 17, 2024

Can I implement this in worker?
And can i use this package to solve this problem?: https://github.com/Klowner/tussle/
And Plz provide example for me

from tussle.

Klowner avatar Klowner commented on July 17, 2024

Can I implement this in worker?

This can be implemented in worker, yes.

You can find examples of listing R2 bucket files in the R2 section of the workers API documentation at Cloudflare: https://developers.cloudflare.com/r2/data-access/workers-api/workers-api-reference/#bucket-method-definitions

The Cloudflare Developers discord is also a good resource for information:
https://discord.com/invite/cloudflaredev

from tussle.

Klowner avatar Klowner commented on July 17, 2024

Version 0.7.0 adds auto-merge support, so completed uploads should now leave an uploaded file as a single R2 record (unless skipMerge: true is passed to the constructor of TussleStorageR2).

from tussle.

Related Issues (10)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.