Skip to content

Commit 7eabdd6

Browse files
author
haverchuck
committed
comments and prettier
1 parent 8dc83cf commit 7eabdd6

File tree

1 file changed

+28
-32
lines changed
  • src/pages/[platform]/build-a-backend/storage/list-files

1 file changed

+28
-32
lines changed

src/pages/[platform]/build-a-backend/storage/list-files/index.mdx

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,9 @@ You can list files without having to download all the files. You can do this by
3737
```javascript
3838
import { list } from 'aws-amplify/storage';
3939

40-
try {
41-
const result = await list({
42-
path: 'photos/',
43-
// Alternatively, path: ({identityId}) => `album/{identityId}/photos/`
44-
});
45-
} catch (error) {
46-
console.log(error);
47-
}
48-
```
40+
try { const result = await list({ path: 'photos/', // Alternatively, path: ({identityId}) => `album/{identityId}/photos/` }); } catch (error) { console.log(error); }
41+
42+
````
4943

5044
Note the trailing slash `/` - if you had requested `list({ path : 'photos' })` it would also match against files like `photos123.jpg` alongside `photos/123.jpg`.
5145

@@ -63,9 +57,9 @@ The format of the response will look similar to the below example:
6357
// ...
6458
],
6559
}
66-
```
67-
{/* in other files we're referring to paths instead of folders, can we be consistent on terminology? */}
68-
Manually created folders will show up as files with a `size` of 0, but you can also match keys against a regex like `file.key.match(/\.[0-9a-z]+$/i)` to distinguish files from folders. Since "folders" are a virtual concept in Amazon S3, any file may declare any depth of folder just by having a `/` in its name.
60+
````
61+
62+
{/* in other files we're referring to paths instead of folders, can we be consistent on terminology? */} Manually created folders will show up as files with a `size` of 0, but you can also match keys against a regex like `file.key.match(/\.[0-9a-z]+$/i)` to distinguish files from folders. Since "folders" are a virtual concept in Amazon S3, any file may declare any depth of folder just by having a `/` in its name.
6963
7064
To access the contents and subpaths of a "folder", you have two options:
7165
@@ -161,13 +155,13 @@ The response will include only the objects within the `photos/` path and will al
161155
162156
The default delimiter character is '/', but this can be changed by supplying a custom delimiter:
163157
164-
```js
165-
const result = await list({
158+
```ts title="src/main.ts"
159+
const result = await list({
166160
// Path uses '-' character to organize files rather than '/'
167-
path: "photos-",
168-
options:{
169-
subpathStrategy: {
170-
strategy:'exclude',
161+
path: 'photos-',
162+
options: {
163+
subpathStrategy: {
164+
strategy: 'exclude',
171165
delimiter: '-'
172166
}
173167
}
@@ -176,8 +170,8 @@ const result = await list({
176170
177171
### More `list` options
178172
179-
Option | Type | Description |
180-
| -- | -- | ----------- |
173+
| Option | Type | Description |
174+
| --- | --- | --- |
181175
| listAll | boolean | Set to true to list all files within the specified `path` |
182176
| pageSize | number | Sets the maximum number of files to be return. The range is 0 - 1000 |
183177
| nextToken | string | Indicates whether the list is being continued on this bucket with a token |
@@ -307,7 +301,7 @@ You can list all of the objects uploaded under a given path by setting the `page
307301
```swift
308302
let options = StorageListRequest.Options(pageSize: 1000)
309303
let listResult = try await Amplify.Storage.list(
310-
path: .fromString("public/example/path"),
304+
path: .fromString("public/example/path"),
311305
options: options
312306
)
313307
listResult.items.forEach { item in
@@ -323,7 +317,7 @@ listResult.items.forEach { item in
323317
let sink = Amplify.Publisher.create {
324318
let options = StorageListRequest.Options(pageSize: 1000)
325319
try await Amplify.Storage.list(
326-
path: .fromString("public/example/path"),
320+
path: .fromString("public/example/path"),
327321
options: options
328322
)
329323
}.sink {
@@ -345,18 +339,19 @@ receiveValue: { listResult in
345339
346340
### More `list` options
347341
348-
Option | Type | Description |
349-
| -- | -- | ----------- |
342+
| Option | Type | Description |
343+
| --- | --- | --- |
350344
| pageSize | UInt | Number between 1 and 1,000 that indicates the limit of how many entries to fetch when retrieving file lists from the server |
351345
| nextToken | String | String indicating the page offset at which to resume a listing. |
352-
346+
353347
</InlineFilter>
354348
355349
<InlineFilter filters={["flutter"]}>
356350
357351
This will list all files located under path `album` that:
358-
* have `private` access level
359-
* are in the root of `album/` (the result doesn't include files under any sub path)
352+
353+
- have `private` access level
354+
- are in the root of `album/` (the result doesn't include files under any sub path)
360355
361356
```dart
362357
Future<void> listAlbum() async {
@@ -412,8 +407,8 @@ Future<void> listAllUnderPublicPath() async {
412407
413408
### More `list` options
414409
415-
Option | Type | Description |
416-
| -- | -- | ----------- |
410+
| Option | Type | Description |
411+
| --- | --- | --- |
417412
| excludeSubPaths | boolean | Whether to exclude objects under the sub paths of the path to list. Defaults to false. |
418413
| delimiter | String | The delimiter to use when evaluating sub paths. If excludeSubPaths is false, this value has no impact on behavior. |
419414
@@ -430,14 +425,15 @@ import { getProperties } from 'aws-amplify/storage';
430425

431426
try {
432427
const result = await getProperties({
433-
path: "album/2024/1.jpg",
428+
path: 'album/2024/1.jpg'
434429
// Alternatively, path: ({ identityId }) => `album/{identityId}/1.jpg`
435430
});
436431
console.log('File Properties ', result);
437432
} catch (error) {
438433
console.log('Error ', error);
439434
}
440435
```
436+
441437
The properties and metadata will look similar to the below example
442438
443439
```js
@@ -453,8 +449,8 @@ The properties and metadata will look similar to the below example
453449
454450
### More `getProperties` options
455451
456-
Option | Type | Description |
457-
| -- | -- | ----------- |
452+
| Option | Type | Description |
453+
| --------------------- | ------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
458454
| useAccelerateEndpoint | boolean | Whether to use accelerate endpoint. | [Transfer Acceleration](/[platform]/build-a-backend/storage/extend-s3-resources/#example---enable-transfer-acceleration) |
459455
460456
<Callout>

0 commit comments

Comments
 (0)