-
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?
Conversation
WalkthroughThe docs file src/routes/docs/products/storage/quick-start/+page.markdoc was updated: the client-web create-file example now imports ID from "appwrite" and uses it for fileId; the server-nodejs example uses the module alias Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 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.
Actionable comments posted: 4
🧹 Nitpick comments (3)
src/routes/docs/products/storage/quick-start/+page.markdoc (3)
49-53
: Standardize Cloud endpoint to include region.Other examples use https://.cloud.appwrite.io/v1. Align Node sample for consistency and fewer 301/geo issues.
Apply this diff:
- .setEndpoint('https://cloud.appwrite.io/v1') + .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
113-116
: Android: import Context (used below).Apply this diff:
import io.appwrite.Client import io.appwrite.services.Storage import io.appwrite.ID +import android.content.Context
226-228
: Flutter download: add missing semicolon after writeAsBytesSync.Small syntax fix.
Apply this diff:
- file.writeAsBytesSync(bytes) + file.writeAsBytesSync(bytes);Additionally, add
import 'dart:io';
at the top of this snippet soFile
resolves.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/routes/docs/products/storage/quick-start/+page.markdoc
(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: tests
🔇 Additional comments (4)
src/routes/docs/products/storage/quick-start/+page.markdoc (4)
23-23
: Good call adding ID import to web example.Makes the ID.unique() usage explicit and copy‑pasteable.
94-110
: Swift sample looks correct.API usage and async/await are consistent.
159-180
: HTTP multipart example: LGTM.Headers, operations/map, and file part look correct.
303-306
: React Native download: object-params confirmed — no change required.Appwrite React Native docs use an object signature for Storage.getFileDownload (bucketId, fileId, optional token); the snippet in src/routes/docs/products/storage/quick-start/+page.markdoc lines 303–306 already matches.
// 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 | ||
}); | ||
``` |
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:
-// 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
-});
-
-// 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
-});
+(async () => {
+ // Node.js: use InputFile
+ const nodeFile = InputFile.fromPath('/path/to/file.jpg', 'file.jpg');
+ const response = await storage.createFile({
+ bucketId: '<BUCKET_ID>',
+ fileId: ID.unique(),
+ file: nodeFile
+ });
+ console.log(response);
+})().catch(console.error);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// 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 | |
}); | |
``` | |
(async () => { | |
// Node.js: use InputFile | |
const nodeFile = InputFile.fromPath('/path/to/file.jpg', 'file.jpg'); | |
const response = await storage.createFile({ | |
bucketId: '<BUCKET_ID>', | |
fileId: ID.unique(), | |
file: nodeFile | |
}); | |
console.log(response); | |
})().catch(console.error); |
🤖 Prompt for AI Agents
In src/routes/docs/products/storage/quick-start/+page.markdoc around lines 56 to
71, the example mixes a browser-only File constructor and uses top-level await
which breaks in CommonJS; remove the browser File example from the
server/Node.js section, keep the InputFile.fromPath usage, and wrap the async
call in an immediately-invoked async function (async () => { ... })() so there
is no top-level await; ensure the code block demonstrates only the Node.js
approach with InputFile.fromPath and await inside the IIFE.
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.
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!
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'), | ||
); | ||
} | ||
``` |
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.
Flutter: make main async before using await.
Current snippet won’t compile as written.
Apply this diff:
-void main() { // Init SDK
+Future<void> main() async { // Init SDK
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
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!
const promise = storage.createFile( | ||
'<BUCKET_ID>', | ||
ID.unique(), | ||
{ | ||
name: 'image.jpg', | ||
type: 'image/jpeg', | ||
size: 1234567, | ||
uri: 'file:///path/to/file.jpg', | ||
} | ||
); |
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!
Summary by CodeRabbit