File persisting using volume in an adonisjs6 project
sajinteractive
PROOP

a year ago

project id ef065e8b-5b3a-4b71-98b9-1c260fe1255a

I am trying to persist file in volume but i'm kind of lost.

i added volume to my service and mounted.

how shall I read and write now?

following code is my drive.ts config

```import env from "#start/env";
import app from "@adonisjs/core/services/app";
import { defineConfig, services } from "@adonisjs/drive";

const driveConfig = defineConfig({
default: env.get("DRIVE_DISK"),

/**

  • The services object can be used to configure multiple file system

  • services each using the same or a different driver.
    */
    services: {
    fs: services.fs({
    location: app.makePath("/storage"),
    serveFiles: true,
    routeBasePath: "/uploads",
    visibility: "public",
    }),
    },
    });

export default driveConfig;

declare module "@adonisjs/drive/types" {
export interface DriveDisks extends InferDriveDisks {}
}```

tried to write a file in following code but failed

```const photoData = request.file("photo", {
// size: '2mb',
extnames: ["jpg", "png", "jpeg"],
});

  const fileName = `${user.id}-user-avatar`;

  personalDetails.photo = fileName;

  photoData?.move(app.makePath("storae/user-profile"), {
    name: fileName,
  });```

following one is for read data

const pc = await disk.get(`app/storage/user-profile/${teamMember.photo}`);

4 Replies

brody
EMPLOYEE

a year ago

can you define what has failed?


sajinteractive
PROOP

a year ago

I can't read or write data

it gives me error

no directory found


sajinteractive
PROOP

a year ago

i have given you codes in the post, would you mind going through this?


brody
EMPLOYEE

a year ago

true using absolute paths


Loading...