@zettasoft/googlestorage

1.0.5 • Public • Published

@zettasoft/googlestorage

คำอธิบาย

  1. ใช้สำหรับอัปโหลดรูปขึ้น Google Storage เท่านั้น
  2. รองรับทั้ง Publish และ Private
  3. รองรับการใช้งานร่วมกับ Multer

วิธีทดสอบ

    npm start

วิธีการใช้งาน

  1. สร้างโปรเจกต์ใน GCS

  2. สร้าง service-google.json

  3. สร้าง .env (ดูตัวอย่าง .env.default)

  4. ใช้งาน

    const storage = new GoogleStorage('YOUR BUCKET NAME'); // GOOGLE_PROJECT_ID ใน .env
    const sourcePath = path.join(__dirname, `YOUR PATH`) // ที่เก็บ Folder รูปภาพ

    const items = await storage.onUploadToStorage(sourcePath, files, { public: true })
    const links = items.map((e) => storage.getPublicUrl(e.mediaPath)) // ดึง URL

หมายเหตุ

  • กรณีที่อยากใช้งาน Private
    const items = await storage.onUploadToStorage(sourcePath, files)
    const links2 = await Promise.all(
        items2.map(async (e) => await storage.getPrivateUrl(e.name, config))
    )

Options

Option Default Description
public false true or false

Readme

Keywords

none

Package Sidebar

Install

npm i @zettasoft/googlestorage

Weekly Downloads

0

Version

1.0.5

License

ISC

Unpacked Size

1.36 MB

Total Files

14

Last publish

Collaborators

  • nlznakub