Skip to content

Commit 9619e24

Browse files
authored
Merge pull request #1941 from appwrite/docs-react-native
Add React Native examples to Storage dos
2 parents c866300 + 3557c85 commit 9619e24

File tree

3 files changed

+279
-53
lines changed

3 files changed

+279
-53
lines changed

src/routes/docs/products/storage/images/+page.markdoc

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ void main() { // Init SDK
106106
//displaying image preview
107107
FutureBuilder(
108108
future: storage.getFilePreview(
109-
bucketId: '[BUCKET_ID]',
110-
fileId: '[FILE_ID]',
109+
bucketId: '<BUCKET_ID>',
110+
fileId: '<FILE_ID>',
111111
), //works for both public file and private file, for private files you need to be logged in
112112
builder: (context, snapshot) {
113113
return snapshot.hasData && snapshot.data != null
@@ -183,5 +183,43 @@ class MainActivity : AppCompatActivity() {
183183
}
184184
}
185185
```
186+
```client-react-native
187+
import { Client, Storage, ImageGravity } from 'react-native-appwrite';
188+
import { Image } from 'react-native';
189+
190+
const client = new Client()
191+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
192+
.setProject('<PROJECT_ID>');
193+
194+
const storage = new Storage(client);
195+
196+
// Get image with transformations
197+
const result = storage.getFilePreview(
198+
'photos', // bucket ID
199+
'sunset.png', // file ID
200+
1800, // width, will be resized using this value
201+
0, // height, ignored when 0
202+
ImageGravity.Center,// crop center
203+
90, // slight compression
204+
5, // border width
205+
'CDCA30', // border color
206+
15, // border radius
207+
1, // full opacity
208+
0, // no rotation
209+
'FFFFFF', // background color
210+
'jpg' // output jpg format
211+
);
212+
213+
console.log(result); // Resource URL
214+
215+
// Usage in a component
216+
const ImagePreview = () => (
217+
<Image
218+
source={{ uri: result.toString() }}
219+
style={{ width: 300, height: 200 }}
220+
resizeMode="contain"
221+
/>
222+
);
223+
```
186224

187225
{% /multicode %}

src/routes/docs/products/storage/quick-start/+page.markdoc

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,33 @@ To upload a file, add this to your app. For web apps, you can use the File objec
117117
}
118118
```
119119

120+
```client-react-native
121+
import { Client, Storage, ID } from 'react-native-appwrite';
122+
123+
const client = new Client()
124+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
125+
.setProject('<PROJECT_ID>');
126+
127+
const storage = new Storage(client);
128+
129+
const promise = storage.createFile(
130+
'<BUCKET_ID>',
131+
ID.unique(),
132+
{
133+
name: 'image.jpg',
134+
type: 'image/jpeg',
135+
size: 1234567,
136+
uri: 'file:///path/to/file.jpg',
137+
}
138+
);
139+
140+
promise.then(function (response) {
141+
console.log(response); // Success
142+
}, function (error) {
143+
console.log(error); // Failure
144+
});
145+
```
146+
120147
```http
121148
POST /v1/storage/buckets/{bucketId}/files HTTP/1.1
122149
Content-Type: multipart/form-data; boundary="cec8e8123c05ba25"
@@ -244,4 +271,18 @@ class MainActivity : AppCompatActivity() {
244271
}
245272
}
246273
```
274+
275+
```client-react-native
276+
import { Client, Storage } from 'react-native-appwrite';
277+
278+
const client = new Client()
279+
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
280+
.setProject('<PROJECT_ID>');
281+
282+
const storage = new Storage(client);
283+
284+
const result = storage.getFileDownload('<BUCKET_ID>', '<FILE_ID>');
285+
286+
console.log(result); // Resource URL
287+
```
247288
{% /multicode %}

0 commit comments

Comments
 (0)