-
Notifications
You must be signed in to change notification settings - Fork 274
Add ID import to storage quick start examples #2417
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,7 +20,7 @@ To upload a file, add this to your app. For web apps, you can use the File objec | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{% multicode %} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
```client-web | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Client, Storage } from "appwrite"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import { Client, Storage, ID } from "appwrite"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const client = new Client() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -39,149 +39,154 @@ To upload a file, add this to your app. For web apps, you can use the File objec | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}, function (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
console.log(error); // Failure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
```` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
```server-nodejs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const sdk = require('node-appwrite'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { InputFile } = require('node-appwrite/file'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { ID } = require('node-appwrite'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const client = new sdk.Client() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setEndpoint('https://cloud.appwrite.io/v1') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setProject('<PROJECT_ID>') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setKey('<API_KEY>'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const storage = new sdk.Storage(client); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// If running in a browser environment, you can use File directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const browserFile = new File(['hello'], 'hello.txt'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await storage.createFile({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bucketId: '<BUCKET_ID>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fileId: ID.unique(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
file: browserFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
```server-nodejs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const sdk = require('node-appwrite'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const { InputFile } = require('node-appwrite/file'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// If running in Node.js, use InputFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const nodeFile = InputFile.fromPath('/path/to/file.jpg', 'file.jpg'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await storage.createFile({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bucketId: '<BUCKET_ID>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fileId: ID.unique(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
file: nodeFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const client = new sdk.Client() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setEndpoint('https://cloud.appwrite.io/v1') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setProject('<PROJECT_ID>') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setKey('<API_KEY>'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
```client-flutter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import 'package:appwrite/appwrite.dart'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const storage = new sdk.Storage(client); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
void main() { // Init SDK | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final client = Client() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.setProject('<PROJECT_ID>'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// If running in a browser environment, you can use File directly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const browserFile = new File(['hello'], 'hello.txt'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await storage.createFile({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bucketId: '<BUCKET_ID>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fileId: ID.unique(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
file: browserFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final storage = Storage(client); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// If running in Node.js, use InputFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const nodeFile = InputFile.fromPath('/path/to/file.jpg', 'file.jpg'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
await storage.createFile({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
final file = await storage.createFile( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bucketId: '<BUCKET_ID>', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fileId: ID.unique(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
file: nodeFile | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
file: InputFile.fromPath(path: './path-to-files/image.jpg', filename: 'image.jpg'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
void main() { // Init SDK | |
final client = Client() | |
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') | |
.setProject('<PROJECT_ID>'); | |
// If running in a browser environment, you can use File directly | |
const browserFile = new File(['hello'], 'hello.txt'); | |
await storage.createFile({ | |
bucketId: '<BUCKET_ID>', | |
fileId: ID.unique(), | |
file: browserFile | |
}); | |
final storage = Storage(client); | |
// If running in Node.js, use InputFile | |
const nodeFile = InputFile.fromPath('/path/to/file.jpg', 'file.jpg'); | |
await storage.createFile({ | |
final file = await storage.createFile( | |
bucketId: '<BUCKET_ID>', | |
fileId: ID.unique(), | |
file: nodeFile | |
}); | |
``` | |
file: InputFile.fromPath(path: './path-to-files/image.jpg', filename: 'image.jpg'), | |
); | |
} | |
``` | |
Future<void> main() async { // Init SDK | |
final client = Client() | |
.setEndpoint('https://<REGION>.cloud.appwrite.io/v1') | |
.setProject('<PROJECT_ID>'); | |
final storage = Storage(client); | |
final file = await storage.createFile( | |
bucketId: '<BUCKET_ID>', | |
fileId: ID.unique(), | |
file: InputFile.fromPath(path: './path-to-files/image.jpg', filename: 'image.jpg'), | |
); | |
} |
🤖 Prompt for AI Agents
In src/routes/docs/products/storage/quick-start/+page.markdoc around lines 76 to
89, the Flutter snippet uses await inside main but declares it as a synchronous
void function; change the signature to an asynchronous main (e.g., Future<void>
main() async) so await is valid, and ensure any necessary async imports (if not
already present) are included so the snippet compiles.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suhasdeshpande valid as well, main is not async
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
React Native signature parity: confirm tuple vs object style.
Other JS SDKs use object params; RN here uses positional args. Verify the installed react-native-appwrite version and align the snippet accordingly.
🌐 Web query:
Does the latest react-native-appwrite Storage.createFile accept object parameters ({ bucketId, fileId, file }) or positional (bucketId, fileId, file)? Cite official docs and show the recommended example.
💡 Result:
Short answer: The current react-native-appwrite SDK uses an options object (named parameters). Example from the official React Native docs shows createFile({ bucketId, fileId, file, permissions }). [1] An older (1.5.x) docs page used positional args (bucketId, fileId, file). [2]
Recommended example (from official React Native docs):
const result = await storage.createFile({
bucketId: '<BUCKET_ID>',
fileId: '<FILE_ID>',
file: await pickSingle(),
permissions: ["read('any')"]
});
console.log(result);. [1]
Sources:
[1] Appwrite — Client React Native Storage (createFile example). (appwrite.io)
[2] Appwrite 1.5.x — Client React Native Storage (positional example). (appwrite.io)
Citations:
- 1: https://appwrite.io/docs/references/cloud/client-react-native/storage?utm_source=openai
- 2: https://appwrite.io/docs/references/1.5.x/client-react-native/storage?utm_source=openai
Update React Native example to use named (options) parameters
Replace the positional-argument example in src/routes/docs/products/storage/quick-start/+page.markdoc (lines 141–150) with the React Native SDK signature that accepts an options object — e.g.:
const result = await storage.createFile({
bucketId: '<BUCKET_ID>',
fileId: ID.unique(),
file: await pickSingle(),
permissions: ["read('any')"]
});
🤖 Prompt for AI Agents
In src/routes/docs/products/storage/quick-start/+page.markdoc around lines 141
to 150, replace the positional-argument React Native example with the SDK's
named options signature: call storage.createFile with a single options object
containing bucketId, fileId (e.g., ID.unique()), file (e.g., await pickSingle()
for RN), and any permissions array (e.g., ["read('any')"]); make the example use
await to capture the result and rename the variable to result to match the
example in the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suhasdeshpande please fix this too, we shifted to using option params everywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix CommonJS top‑level await and remove browser‑only File usage in server‑nodejs block.
Top‑level await is invalid with require(); and File(['...']) is browser‑only. Keep the Node path using InputFile and wrap in an async IIFE.
Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@suhasdeshpande this is a valid review, seems like we are showing browser file in nodejs block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.