You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pages/[platform]/build-a-backend/storage/copy-files/index.mdx
+42-5Lines changed: 42 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -66,11 +66,48 @@ Cross identity ID copying is only allowed if the destination path has the the ri
66
66
67
67
</Callout>
68
68
69
-
### More `copy` options
69
+
##Specify a bucket or copy across buckets / regions
70
70
71
-
Option | Type | Description | Reference Links |
72
-
| -- | -- | ----------- | -- |
73
-
| useAccelerateEndpoint | boolean | Whether to use accelerate endpoint. |[Transfer Acceleration](/[platform]/build-a-backend/storage/extend-s3-resources/#example---enable-transfer-acceleration)|
71
+
You can also perform an `copy` operation to a specific bucket by providing the `bucket` option. This option can either be a string representing the target bucket's assigned name in Amplify Backend or an object specifying the bucket name and region from the console.
72
+
73
+
```javascript
74
+
import { copy } from'aws-amplify/storage';
75
+
76
+
constcopyFile=async () => {
77
+
try {
78
+
constresponse=awaitcopy({
79
+
source: {
80
+
path:'album/2024/1.jpg',
81
+
// Specify a target bucket using name assigned in Amplify Backend
82
+
// or bucket name from console and associated region
83
+
bucket:'assignedNameInAmplifyBackend'
84
+
},
85
+
destination: {
86
+
path:'shared/2024/1.jpg',
87
+
// Specify a target bucket using name assigned in Amplify Backend
88
+
// or bucket name from console and associated region
89
+
bucket: {
90
+
bucketName:'generated-second-bucket-name',
91
+
region:'us-east-2'
92
+
}
93
+
}
94
+
});
95
+
} catch (error) {
96
+
console.error('Error', err);
97
+
}
98
+
};
99
+
```
100
+
101
+
<Callout>
102
+
In order to copy to or from a bucket other than your default, both source and destination must have `bucket` explicitly defined.
103
+
</Callout>
104
+
105
+
## Copy `source` and `destination` options
106
+
107
+
Option | Type | Default | Description |
108
+
| -- | :--: | :--: | ----------- |
109
+
| path | string \| <br/>(\{ identityId \}) => string | Required | A string or callback that represents the path in source and destination bucket to copy the object to or from |
110
+
| bucket | string \| <br />\{ bucketName: string;<br/> region: string; \}| Default bucket and region from Amplify configuration | A string representing the target bucket's assigned name in Amplify Backend or an object specifying the bucket name and region from the console.<br/><br/>Read more at [Configure additional storage buckets](/[platform]/build-a-backend/storage/set-up-storage/#configure-additional-storage-buckets). |
Inside your template or JSX code, you can use the `url` property to create a link to the file:
84
78
85
79
```tsx
@@ -94,13 +88,34 @@ This function does not check if the file exists by default. As result, the signe
94
88
95
89
</Callout>
96
90
97
-
### More `getUrl` options
91
+
### More getUrl options
98
92
99
-
Option | Type | Description |
100
-
| -- | -- | ----------- |
101
-
| useAccelerateEndpoint | boolean | Whether to use accelerate endpoint. <br/><br/> Read more at [Transfer Acceleration](/[platform]/build-a-backend/storage/extend-s3-resources/#example---enable-transfer-acceleration)||
102
-
| validateObjectExistence | boolean | Whether to head object to make sure the object existence before downloading. Defaults to false |
103
-
| expiresIn | number | Number of seconds till the URL expires. <br/><br/> The expiration time of the presigned url is dependent on the session and will max out at 1 hour. |
93
+
The behavior of the `getUrl` API can be customized by passing in options.
94
+
95
+
```typescript
96
+
import { getUrl } from'aws-amplify/storage';
97
+
98
+
const linkToStorageFile =awaitgetUrl({
99
+
path: "album/2024/1.jpg",
100
+
options: {
101
+
// specify a target bucket using name assigned in Amplify Backend
102
+
bucket: 'assignedNameInAmplifyBackend',
103
+
// ensure object exists before getting url
104
+
validateObjectExistence: true,
105
+
// url expiration time in seconds.
106
+
expiresIn: 300,
107
+
// whether to use accelerate endpoint
108
+
useAccelerateEndpoint: true,
109
+
}
110
+
});
111
+
```
112
+
113
+
Option | Type | Default | Description |
114
+
| :--: | :--: | :--: | ----------- |
115
+
| bucket | string \| <br />\{ bucketName: string;<br/> region: string; \} | Default bucket and region from Amplify configuration | A string representing the target bucket's assigned name in Amplify Backend or an object specifying the bucket name and region from the console.<br/><br/>Read more at [Configure additional storage buckets](/[platform]/build-a-backend/storage/set-up-storage/#configure-additional-storage-buckets)
116
+
| validateObjectExistence | boolean | false | Whether to head object to make sure the object existence before downloading. |
117
+
| expiresIn | number | 900 | Number of seconds till the URL expires. <br/><br/> The expiration time of the presigned url is dependent on the session and will max out at 1 hour. |
118
+
| useAccelerateEndpoint | boolean | false | Whether to use accelerate endpoint. <br/><br/> Read more at [Transfer Acceleration](/[platform]/build-a-backend/storage/extend-s3-resources/#example---enable-transfer-acceleration)|
104
119
105
120
</InlineFilter>
106
121
@@ -296,18 +311,7 @@ import { downloadData } from 'aws-amplify/storage';
296
311
297
312
// Downloads file content to memory
298
313
const { body, eTag } =awaitdownloadData({
299
-
path:"/album/2024/1.jpg",
300
-
options: {
301
-
// optional progress callback
302
-
onProgress: (event) => {
303
-
console.log(event.transferredBytes);
304
-
}
305
-
// optional bytes range parameter to download a part of the file, the 2nd MB of the file in this example
306
-
bytesRange: {
307
-
start:1024,
308
-
end:2048
309
-
}
310
-
}
314
+
path:"album/2024/1.jpg"
311
315
}).result;
312
316
```
313
317
</InlineFilter>
@@ -505,7 +509,7 @@ import { downloadData } from 'aws-amplify/storage';
505
509
506
510
try {
507
511
const downloadResult = await downloadData({
508
-
path:"/album/2024/1.jpg"
512
+
path:"album/2024/1.jpg"
509
513
}).result;
510
514
const text = await downloadResult.body.text();
511
515
// Alternatively, you can use `downloadResult.body.blob()`
@@ -569,6 +573,45 @@ let resultSink = downloadTask
You can also perform an upload operation to a specific bucket by providing the `bucket` option. You can pass in a string representing the target bucket's assigned name in Amplify Backend.
580
+
581
+
```ts
582
+
import { downloadData } from 'aws-amplify/storage';
583
+
584
+
const result = await downloadData({
585
+
path: 'album/2024/1.jpg',
586
+
options: {
587
+
// highlight-start
588
+
// Specify a target bucket using name assigned in Amplify Backend
589
+
bucket: 'assignedNameInAmplifyBackend'
590
+
// highlight-end
591
+
}
592
+
}).result;
593
+
594
+
```
595
+
Alternatively, you can also pass in an object by specifying the bucket name and region from the console.
596
+
597
+
```ts
598
+
import { downloadData } from 'aws-amplify/storage';
599
+
600
+
const result = await downloadData({
601
+
path: 'album/2024/1.jpg',
602
+
options: {
603
+
// highlight-start
604
+
// Alternatively, provide bucket name from console and associated region
605
+
bucket: {
606
+
bucketName: 'bucket-name-from-console',
607
+
region: 'us-east-2'
608
+
}
609
+
// highlight-end
610
+
}
611
+
}).result;
612
+
613
+
```
614
+
572
615
### Monitor download progress
573
616
574
617
```javascript
@@ -577,7 +620,7 @@ import { downloadData } from 'aws-amplify/storage';
The behavior of the `downloadData` API can be customized by passing in options.
953
+
954
+
```javascript
955
+
import { downloadData } from 'aws-amplify/storage';
956
+
957
+
// Downloads file content to memory
958
+
const { body, eTag } = await downloadData({
959
+
path:"album/2024/1.jpg",
960
+
options: {
961
+
// optional bytes range parameter to download a part of the file, the 2nd MB of the file in this example
962
+
bytesRange: {
963
+
start:1024,
964
+
end:2048
965
+
},
966
+
useAccelerateEndpoint:true,
967
+
}
968
+
}).result;
969
+
970
+
```
908
971
909
-
Option | Type | Description | Reference Links |
910
-
| -- | -- | ----------- | -- |
911
-
| useAccelerateEndpoint | boolean | Whether to use accelerate endpoint. | [Transfer Acceleration](/[platform]/build-a-backend/storage/extend-s3-resources/#example---enable-transfer-acceleration) |
912
-
| bytesRange | \{ start: number; end:number; \} | bytes range parameter to download a part of the file. | |
913
-
| onProgress | callback | Callback function tracking the upload/download progress. | |
972
+
Option|Type|Default|Description|
973
+
|:--:|:--:|:--:|-----------|
974
+
| bucket | string \|<br />\{ bucketName: string;<br/> region: string; \} |Default bucket and region from Amplify configuration |A string representing the target bucket's assigned name in Amplify Backend or an object specifying the bucket name and region from the console.<br/><br/>Read more at [Configure additional storage buckets](/[platform]/build-a-backend/storage/set-up-storage/#configure-additional-storage-buckets) |
975
+
| onProgress | callback | — | Callback function tracking the upload/download progress. |
976
+
| bytesRange | \{ start: number; end:number; \} | — | Bytes range parameter to download a part of the file. |
977
+
| useAccelerateEndpoint | boolean | false | Whether to use accelerate endpoint.<br/><br/>Read more at [Transfer Acceleration](/[platform]/build-a-backend/storage/extend-s3-resources/#example---enable-transfer-acceleration) |
0 commit comments