Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Logo - Strapi Provider Upload - Arweave

Strapi Provider Upload Arweave

Arweave Provider for Strapi Upload

NPM version Monthly download on NPM

πŸ“‹ Table of Contents

πŸ“¦ Installation

With npm:

npm install @longviewlabs/strapi-provider-upload-arweave --save

❓ What is Arweave?

Arweave is a decentralized network designed for long-term data storage.

Users pay upfront for uploads based on a calculated storage cost, and Arweave provides guarantees of data replication and storage for a minimum of 200 years. Uploads are immutable and can't be removed.

Data stored on Arweave can be accessed just like any other data using a modern web browser. Take a look at this JSON file stored on Arweave here.

These properties make Arweave an ideal storage option for storing Strapi media files.

πŸ’³ Get your first Arweave Wallet

Data uploads on Arweave cost AR tokens ($AR). You can get an approximation of your data storage costs using this fee calculator here.

To subsidize and handle data uploads to Arweave, you will need an Arweave wallet. To get started, install Wander β€” you can download either the browser extension or mobile application, and follow the steps to set up a new wallet.

πŸ’Ύ Downloading the wallet keyfile

Once you've set up a wallet, you will need to download a keyfile.

While Wander acts as a GUI to perform data uploads, the keyfile can be used in a more API-like fashion to help facilitate data uploads from within programs such as Strapi.

To download your keyfile:

  1. Open Wander.
  2. Click the "Menu" button in the bottom-left corner (on the browser extension).
  3. Click "Manage Accounts".
  4. Select your account.
  5. Click "Export Keyfile" and enter your password.
  6. Click "Export".

A modal should appear to download your keyfile, which ends in .json. This should be stored securely.

Here's the content of a JWK file, which describes an RSA-PSS key-pair. Note that the values are abbreviated:

{
  "d": "cgeeu66FlfX9wVgZr5AXKlw4MxTlxSuSwMtTR7mqcnoE...",
  "dp": "DezP9yvB13s9edjhYz6Dl...",
  "dq": "SzAT5DbV7eYOZbBkkh20D...",
  "e": "AQAB",
  "ext": true,
  "kty": "RSA",
  "n": "o4FU6y61V1cBLChYgF9O37S4ftUy4newYWLApz4CXlK8...",
  "p": "5ht9nFGnpfW76CPW9IEFlw...",
  "q": "tedJwzjrsrvk7o1-KELQxw...",
  "qi": "zhL9fXSPljaVZ0WYhFGPU..."
}

Warning

Anyone with your keyfile can control all of the assets within an Arweave wallet β€” make sure to keep it secure and private (i.e., do not commit it to GitHub repos or expose it publicly, etc.).

πŸ”’ Setting up Strapi Configuration

Once you have downloaded your Arweave wallet keyfile, copy its content and set it as the ARWEAVE_WALLET environment variable in your Strapi application. After that, edit the ./config/plugins.js file to configure the upload provider.

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: 'arweave',
      providerOptions: {
        arweaveWallet: env.json('ARWEAVE_WALLET'), // Content of the Arweave wallet JWK
        gateway: env('ARWEAVE_GATEWAY', 'https://arweave.net'), // Optional: Arweave Gateway URL, default is 'https://arweave.net'
      },
    },
  },
  // ...
});

πŸ”’ Setting up strapi::security middlewares to avoid CSP blocked URLs

Edit ./config/middlewares.js:

  • In the fields img-src and media-src, add the Arweave Gateway URL.
module.exports = [
  'strapi::errors',
  {
    name: 'strapi::security',
    config: {
      contentSecurityPolicy: {
        useDefaults: true,
        directives: {
          'connect-src': ["'self'", 'https:'],
          'img-src': ["'self'", 'data:', 'blob:', 'arweave.net', '*.arweave.net'],
          'media-src': ["'self'", 'data:', 'blob:', 'arweave.net', '*.arweave.net'],
          upgradeInsecureRequests: null,
        },
      },
    },
  },
  'strapi::cors',
  'strapi::poweredBy',
  'strapi::logger',
  'strapi::query',
  'strapi::body',
  'strapi::favicon',
  'strapi::public',
];

πŸ“ Provider configuration options

The following options are available to configure the Arweave upload provider in Strapi:

arweaveWallet

The content of an Arweave wallet JWK (JSON Web Key) file. This is used to sign transactions and upload files to Arweave.

gateway

The URL of the Arweave gateway to use for accessing files. This is optional, and if not provided, the default gateway https://arweave.net will be used.

  • Default value: https://arweave.net
  • Optional

getContentType

A function that is executed to get the content type for a file when it is uploaded.

When no function is provided, the following content type is used:

file.mime
  • Default value: undefined
  • Optional

Example:

  getContentType: (file: File) => file.mime;

❓ FAQ

How to pay for uploads

Uploads to Arweave through this Strapi provider are facilitated by ArDrive's Turbo upload service. ArDrive Turbo bundles data uploads together and submits them to Arweave.

ArDrive Turbo uses Turbo Credits to pay for uploads. You can top up your account by logging in to Turbo Topup with your Wander wallet, or use the CLI tool. There are more detailed instructions here.

Tip

All uploads under 100KB are subsidised, meaning they are free. However, you will need to top up your account to pay for larger uploads.

πŸ”— Links

πŸ’¬ Community support

πŸ“„ License

See the MIT License file for licensing information.

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages