ENF News Bot
Automated News Bot
- Joined
- Apr 15, 2022
- Messages
- 2,591
Use the Images binding to upload, list, retrieve, update, and delete images stored in Images directly from your Worker without managing API tokens or making HTTP requests.
The
For example, you can upload an image from a request body and return its metadata:
Or retrieve and serve the original bytes of a hosted image:
For more information, refer to the Images binding.
Continue reading...
The
env.IMAGES.hosted namespace supports the following storage and management operations:.upload(image, options)— Upload a new image to your account..list(options)— List images with pagination..image(imageId).details()— Get image metadata..image(imageId).bytes()— Stream the original image bytes..image(imageId).update(options)— Update metadata or access controls..image(imageId).delete()— Delete an image.
For example, you can upload an image from a request body and return its metadata:
Code:
const image = await env.IMAGES.hosted.upload(request.body, {
filename: "upload.jpg",
metadata: { source: "worker" },
});
return Response.json(image);
Or retrieve and serve the original bytes of a hosted image:
Code:
const bytes = await env.IMAGES.hosted.image("IMAGE_ID").bytes();
return new Response(bytes);
For more information, refer to the Images binding.
Continue reading...