Skip to content

Commit 67044f2

Browse files
authored
fix(js): add storage callout to encode copy source URI (#8085)
1 parent a688ede commit 67044f2

File tree

1 file changed

+11
-5
lines changed
  • src/pages/[platform]/build-a-backend/storage/copy-files

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,25 @@ const copyFile = async () => {
4646
try {
4747
const response = await copy({
4848
source: {
49-
path: 'album/2024/1.jpg',
50-
// Alternatively, path: ({identityId}) => `album/{identityId}/1.jpg`
49+
path: `album/2024/${encodeURIComponent('#1.jpg')}`,
50+
// Alternatively, path: ({identityId}) => `album/${identityId}/${encodeURIComponent('#1.jpg')`
5151
},
5252
destination: {
53-
path: 'shared/2024/1.jpg',
54-
// Alternatively, path: ({identityId}) => `shared/{identityId}/1.jpg`
53+
path: 'shared/2024/#1.jpg',
54+
// Alternatively, path: ({identityId}) => `shared/${identityId}/#1.jpg`
5555
},
5656
});
5757
} catch (error) {
5858
console.error('Error', err);
5959
}
6060
};
6161
```
62+
<Callout>
63+
64+
The operation can fail if there's a special character in the `source` path. You should URI encode the source
65+
path with special character. You **don't** need to encode the `destination` path.
66+
67+
</Callout>
6268

6369
<Callout>
6470

@@ -106,7 +112,7 @@ In order to copy to or from a bucket other than your default, both source and de
106112

107113
Option | Type | Default | Description |
108114
| -- | :--: | :--: | ----------- |
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 |
115+
| 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. <br /> **Each segment of the path in `source` must by URI encoded.** |
110116
| 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). |
111117

112118
</InlineFilter>

0 commit comments

Comments
 (0)