Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Amazon S3 Essentials

You're reading from   Amazon S3 Essentials Get started with Amazon S3 for virtually unlimited cloud and Internet storage

Arrow left icon
Product type Paperback
Published in Nov 2015
Publisher Packt
ISBN-13 9781783554898
Length 112 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
 Gulabani Gulabani
Author Profile Icon Gulabani
Gulabani
Arrow right icon
View More author details
Toc

Folder

To create a folder, we need to have a bucket. We cannot create a folder at the root level. Folders can be nested. To create a folder under the bucket, we need to create an object with its content length metadata as 0 and an empty content so that it can be recognized as a folder:

ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(0);

InputStream emptyContent = new ByteArrayInputStream(new byte[0]);

PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, folderName + "/", emptyContent, metadata);

s3.putObject(putObjectRequest);

In the preceding code, you can see that the content length is set to 0, and an empty byte array input has been added. Apart from this, we provided the suffix "/" to the folder name so that we will be able to distinguish between the folder and the object inside the folder.

The following is the complete code to create a folder in a bucket:

package com.chapter3;

import java.io.ByteArrayInputStream;
import...
lock icon The rest of the chapter is locked
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Amazon S3 Essentials
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon