Upload media to digitalocean spaces using strapi v4

because thefrontend mentioned that it is possible. and in the docs is clearly stated, that one can use it with s3 compatible services

Did you get any error in your server logs? Does the upload folder show preview images?

no errors - i get preview images and everything is located in the /upload/ folder

Can you check the link of an image? Looks like they are stored somewhere else.

the URL is /upload/*******. it seems like the plugin is not used

looks like they are stored locally. Can you show the dependencies in your package.json file?

{
  "name": "########",
  "private": true,
  "version": "0.1.0",
  "description": "A Strapi application",
  "scripts": {
    "develop": "strapi develop",
    "start": "strapi start",
    "build": "strapi build",
    "strapi": "strapi"
  },
  "dependencies": {
    "@_sh/strapi-plugin-ckeditor": "^1.1.2",
    "@strapi/plugin-i18n": "4.3.6",
    "@strapi/plugin-users-permissions": "4.3.6",
    "@strapi/provider-upload-aws-s3": "^4.3.6",
    "@strapi/strapi": "4.3.6",
    "better-sqlite3": "7.4.6",
    "pg": "^8.7.3",
    "pg-connection-string": "^2.5.0"
  },
  "author": {
    "name": "A Strapi developer"
  },
  "strapi": {
    "uuid": "a9db7f52-8e24-42c1-9231-1144e1ab9d27"
  },
  "engines": {
    "node": ">=12.x.x <=16.x.x",
    "npm": ">=6.0.0"
  },
  "license": "MIT"
}

That looks ok. However, there must be something misconfigured as the files seem to be uploaded locally. I suggest double checking the plugin.js file if there is any other or older upload plugin activated. Maybe deleting node modules and reinstalling will help, too.

You could also try replacing “^4.3.6” with “4.3.6” (without the ^) and run npm i again

Is it possible to test it locally? Should i be able to push from my local dev machine to DO Spaces if i enabled it?

also this is my complete plugin.js

module.exports = ({env}) => ({
    chkeditor: true,
    upload: {
        config: {
            provider: 'aws-s3',
            providerOptions: {
                accessKeyId: env('DO_SPACE_ACCESS_KEY'),
                secretAccessKey: env('DO_SPACE_SECRET_KEY'),
                endpoint: env('DO_SPACE_ENDPOINT'),
                params: {
                    Bucket: env('DO_SPACE_BUCKET'),
                },
            },
            actionOptions: {
                upload: {},
                uploadStream: {},
                delete: {},
            },
        },
    },
})

i don’t see any errors, it just loads the files in the local file system and doesn’t attempt using anything other. Do i need to set some sort of config i am missing?

maybe there’s a typo here? Should be ckeditor: true
The upload plugin should also work locally.

you’re right there was a typo. But that didn’t solved the problem

I have tested this and it works fine for me.
Are you sure, your env vars are define correctly in your instance at digital ocean.

However, I am still facing issues with video previews.
which has been reported at Location URL misses https:// ¡ Issue #4196 ¡ aws/aws-sdk-js ¡ GitHub

Hi Fabian, are you still having a problem? Make sure your config files are plugins.js and middlewares.js with the “s”.

Everything is named correctly and I have all the env vars set up. I don’t know what’s the problem, but we now use a droplet, so we don’t need spaces.

Thanks for your help. If I have more time in the future I’ll try it again and come back if I have a solution

To re-inforce @Fabian_Clemenz struggles here there is definitely an issue getting strapi 4.4.5 and digital ocean spaces to play nicely. I have followed the above with both strapi-provider-upload-dos and strapi/provider-upload-aws-s3 … no files show up in spaces. Any alternative apporaches please share, also followed this guide:

https://levelup.gitconnected.com/next-js-strapi-deploy-my-portfolio-website-to-vercel-and-digital-ocean-8011d5965038

Hi All, There was an update to the AWS-s3 provider in the latest version of Strapi (4.4.7). This was specifically to solve a problem with the https:// protocol being dropped on larger video files. I have also added a repository to my personal GitHub account that has a basic project setup for DO app platform and DO spaces. See the ./config/env/production directory for most everything you need. In the DO AppPlatform you need to set the env variables. I think I ended up with 10-12 but reply if you have any issues.

  • One change is in the security middleware there need to be two different allowed addresses because DO doesn’t serve them in a consistent format:
'*.fra1.digitaloceanspaces.com',
 'fra1.digitaloceanspaces.com',

(edit to add) You need to change fra1 to whatever your Spaces server is (e.g. nyc1, ams2, lon1)

Here is the GitHub repo

2 Likes

Yes! updating to 4.4.7 and following the config in your middlewares.js - its all working. Even tested with mp4 - thank you!

2 Likes