Skip to content

Add React Native examples to Storage dos #1941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 30, 2025
Merged
42 changes: 40 additions & 2 deletions src/routes/docs/products/storage/images/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ void main() { // Init SDK
//displaying image preview
FutureBuilder(
future: storage.getFilePreview(
bucketId: '[BUCKET_ID]',
fileId: '[FILE_ID]',
bucketId: '<BUCKET_ID>',
fileId: '<FILE_ID>',
), //works for both public file and private file, for private files you need to be logged in
builder: (context, snapshot) {
return snapshot.hasData && snapshot.data != null
Expand Down Expand Up @@ -183,5 +183,43 @@ class MainActivity : AppCompatActivity() {
}
}
```
```client-react-native
import { Client, Storage, ImageGravity } from 'react-native-appwrite';
import { Image } from 'react-native';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const storage = new Storage(client);

// Get image with transformations
const result = storage.getFilePreview(
'photos', // bucket ID
'sunset.png', // file ID
1800, // width, will be resized using this value
0, // height, ignored when 0
ImageGravity.Center,// crop center
90, // slight compression
5, // border width
'CDCA30', // border color
15, // border radius
1, // full opacity
0, // no rotation
'FFFFFF', // background color
'jpg' // output jpg format
);

console.log(result); // Resource URL

// Usage in a component
const ImagePreview = () => (
<Image
source={{ uri: result.toString() }}
style={{ width: 300, height: 200 }}
resizeMode="contain"
/>
);
```

{% /multicode %}
41 changes: 41 additions & 0 deletions src/routes/docs/products/storage/quick-start/+page.markdoc
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,33 @@ To upload a file, add this to your app. For web apps, you can use the File objec
}
```

```client-react-native
import { Client, Storage, ID } from 'react-native-appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const storage = new Storage(client);

const promise = storage.createFile(
'<BUCKET_ID>',
ID.unique(),
{
name: 'image.jpg',
type: 'image/jpeg',
size: 1234567,
uri: 'file:///path/to/file.jpg',
}
);

promise.then(function (response) {
console.log(response); // Success
}, function (error) {
console.log(error); // Failure
});
```

```http
POST /v1/storage/buckets/{bucketId}/files HTTP/1.1
Content-Type: multipart/form-data; boundary="cec8e8123c05ba25"
Expand Down Expand Up @@ -244,4 +271,18 @@ class MainActivity : AppCompatActivity() {
}
}
```

```client-react-native
import { Client, Storage } from 'react-native-appwrite';

const client = new Client()
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
.setProject('<PROJECT_ID>');

const storage = new Storage(client);

const result = storage.getFileDownload('<BUCKET_ID>', '<FILE_ID>');

console.log(result); // Resource URL
```
{% /multicode %}
Loading