0

its a bit confusing to upload a photo and access it from appwrite storage, I have created photo buckets in the app and I have copied the code of the preview image from the console and pasted in vscode to run, but as I'm very new to this I couldn't figure out, if I should be using the 'get' method as shown in the console , and the function I should be executing should be buckets.create right? please help me with any link of process or just give me some hints to move further .

Thank you

  • What Appwrite SDK are you using and what version is it? What version is Appwrite? – Steven Nguyen Oct 20 '22 at 06:12
  • its 1.1.1 ,im using node-appwrite. yes yes i can upload through the appwrite,but how do I access that through vscode? – Mohammed Aquib Hussain Oct 21 '22 at 10:31
  • 1.1.1 of Appwrite? The latest is 1.0.3 . What version of the node-appwrite SDK? – Steven Nguyen Oct 21 '22 at 15:54
  • Well in my terminal it is giving me the same thing if I give appwrite -version, However, what I meant to ask is,how can parse the data(photos uploaded in appwrite)into the vs code? like adjusting or viewing its pixcels or any other stuff like that..I'm wondering how the code could possibly look like?! – Mohammed Aquib Hussain Oct 26 '22 at 13:28
  • `appwrite -v ` gives you the version of the Appwrite CLI, not your Appwrite server. To find out the version of your Appwrite server, go to the Appwrite Web Console and look at the bottom of the page. Alternatively, you can look at the docker image version in your Appwrite docker-compose.yml file or in the output of `docker ps`. – Steven Nguyen Oct 27 '22 at 03:10

1 Answers1

0

Using version 8.1.0 of the Appwrite Node SDK on Appwrite version 1.0.x, you would create a file with the Create File API like this:

const { Client, Databases, Storage, InputFile, ID } = require('node-appwrite');

const client = new Client()
    .setEndpoint('https://[HOSTNAME or IP]/v1')
    .setProject('[PROJECT ID]')
    .setKey('[API KEY]');

const storage = new Storage(client);

const file = await storage.createFile(
    '[BUCKET ID]',
    ID.unique(),
    InputFile.fromPath("./resources/nature.jpg", "nature.jpg"),
    [
        Permission.read(Role.any()),
        Permission.update(Role.users()),
        Permission.delete(Role.users()),
    ]
);

To download a file, you would use the Get File for Download API like this:

const buffer = await storage.getFileDownload('[BUCKET ID]', file.$id);

buffer is a Buffer and you can do whatever you need with it like writing it to disk.

Steven Nguyen
  • 452
  • 4
  • 4