Back

How can i access the file url and preview the image. I use Nest.JS[Server] for uploading image

  • 0
  • Storage
  • Cloud
Coo_Mar
3 Aug, 2024, 12:41

i get this as response after uploading the image

πŸš€ ~ MemberinfoService ~ createmember ~ results: [ { '$id': '66ae214f3b8ac191d498', bucketId: '66acfe76001a5d8eadc2', '$createdAt': '2024-08-03T12:23:43.686+00:00', '$updatedAt': '2024-08-03T12:23:43.686+00:00', '$permissions': [], name: 'Screenshot from 2024-08-02 19-37-04.png', signature: '5e543256c480ac577d30f76f9120eb74', mimeType: 'text/plain', sizeOriginal: 9, chunksTotal: 1, chunksUploaded: 1, fileUrl: '[object Object]' }, { '$id': '66ae214f1d2e6be28790', bucketId: '66acfe76001a5d8eadc2', '$createdAt': '2024-08-03T12:23:44.249+00:00', '$updatedAt': '2024-08-03T12:23:44.249+00:00', '$permissions': [], name: 'Screenshot from 2024-08-02 20-53-29.png', signature: '5e543256c480ac577d30f76f9120eb74', mimeType: 'text/plain', sizeOriginal: 9, chunksTotal: 1, chunksUploaded: 1, fileUrl: '[object Object]' } ]

when i try to upload the image

https://cloud.appwrite.io/v1/storage/buckets/66acfe76001a5d8eadc2/files/66ae214f1d2e6be28790/preview?project=66acfde6002b199f0655

it response with

{ "message": "The requested file could not be found.", "code": 404, "type": "storage_file_not_found", "version": "1.5.8" }

also in file security i have enable it and tick all the permissions

TL;DR
Developers uploads image to Appwrite using Nest.JS but face issue with accessing file URLs for image preview. The response received includes 'fileUrl' as '[object Object]' causing a 'file not found' error when trying to preview the image. **Solution:** - Update the code to properly handle the 'fileUrl' response in JSON format. - When uploading the image, ensure all permissions are correctly set in the file security settings.
Coo_Mar
3 Aug, 2024, 12:42

How can i access the file url and preview the image. I use Nest.JS[Server] for uploading image

Coo_Mar
3 Aug, 2024, 12:47

// appwrite.service.ts import { Injectable } from '@nestjs/common'; import { Client, Storage } from 'node-appwrite';

@Injectable() export class AppwriteService { private client: Client; private storage: Storage;

constructor() { this.client = new Client() .setEndpoint('https://cloud.appwrite.io/v1') // Your API Endpoint .setProject(process.env.APP_WRITE_PROJECTID) // Your project ID .setKey(process.env.APP_WRITE_KEY); // Your secret API key

TypeScript
this.storage = new Storage(this.client);

}

async appWriteUploadFile( file: Express.Multer.File, bucketId: string, ): Promise<any> { try { const fileData = new File([file.buffer], file.originalname, { type: file.mimetype, }); const response = await this.storage.createFile( bucketId, 'unique()', // You can use a custom ID or 'unique()' for auto-generated ID fileData, ); console.log('πŸš€ ~In Service AppwriteService ~ response:', response); return response; } catch (error) { throw error; } } } }

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more