Comments (4)
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.
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.
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.
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)
- Help write unit tests
- Use crypto.DigestStream in CF Worker environments for chunk checksums
- can we publish packages for tussle components HOT 4
- Does it make sense to use cloudflare worker kv statestore for r2 uploads HOT 2
- Implement termination extension
- Cloudflare R2 example HOT 4
- cloudflare s3 example maybe broken HOT 4
- Handle PATCH offset mismatch with 409 Conflict
- Store write failures should result in 500 or 503 response HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tussle.