gpt4 book ai didi

Strapi not uploading pictures to Cloudinary(Strapi不向Cloudinary上传图片)

转载 作者:bug小助手 更新时间:2023-10-28 20:34:09 25 4
gpt4 key购买 nike



UPDATE: I installed Strapi version 3.6.3 and it works well

更新:我安装了Strapi 3.6.3版,运行良好


Strapi - Clouinary connection do not work for me. So I'm uploading pictures to Stapi, but they don't appear in Clouinary.

Strapi-Clouary连接对我不起作用。所以我正在把照片上传到Stapi,但它们不会出现在Clouary中。


In config folder I created file plugins.js with following content:

在配置文件夹中,我创建了包含以下内容的plugins.js文件:


module.exports = ({
env
}) => ({
// ...
upload: {
provider: 'cloudinary',
providerOptions: {
cloud_name: env('CLOUDINARY_NAME'),
api_key: env('CLOUDINARY_KEY'),
api_secret: env('CLOUDINARY_SECRET'),
},
},
// ...
});

I have installed npm i strapi-provider-upload-cloudinary

我已经安装了NPM I stapi-Provider-Upload-Cloudinary


then changed file .env to

然后将文件.env更改为


PORT=1337
CLOUDINARY_NAME="***"
CLOUDINARY_KEY="***"
CLOUDINARY_SECRET="***"```

Actually automatically following code added automatically:
```JWT_SECRET=*********
API_TOKEN_SALT=*********
JWT_SECRET=*********

What could be a problem?
should CLOUDINARY_SECRET be in "quotes"? or in 'quotes' or without quotes?

会有什么问题呢?CLOUDINARY_SECRET应该在“QUOTES”中吗?或者放在‘引号’里,或者不带引号?


Terminal output after adding image is following:

添加图片后的终端输出如下:


http://localhost:1337

[2021-12-07 02:10:14.702] http: POST /upload (261 ms) 200
[2021-12-07 02:10:14.744] http: GET /upload/files?sort=updatedAt:DESC&page=1&pageSize=10 (24 ms) 200
[2021-12-07 02:10:14.758] http: GET /uploads/thumbnail_Screenshot_2021_11_26_130226_11a95e81ea.png?width=1504&height=1258 (4 ms) 200

All permissions seems to be set...

所有权限似乎都已设置...


Also created extentions/upload/config/setting.json with the following content:

还创建了扩展/Upload/CONFIG/setting.json,内容如下:


    "provider": "cloudinary",
"providerOptions": { "cloud_name":"devert0mt",
"api_key": "***",
"api_secret":"***"
}
}{
"provider": "cloudinary",
"providerOptions": { "cloud_name":"devert0mt",
"api_key": "***",
"api_secret":"***"
}
}```

更多回答

You shouldn't post your Cloudinary API Secret publicly. I recommend changing your current access keys ASAP. This can be done on the security tab on your Cloudinary dashboard.

你不应该公开发布你的Cloudinary API密钥。我建议尽快更改您当前的访问密钥。这可以在Cloudinary仪表板上的安全选项卡上完成。

I believe the keys should be without quotes. And I second what @RoeeBen-Ari said previously: never post your secret keys publicly. There's a reason they're called secret keys... Obtain new keys from Cloudinary and remove the ones you posted ASAP.

我相信钥匙应该没有引号。我赞同@RoeeBen-Ari之前说过的话:永远不要公开发布你的密钥。它们被称为秘密钥匙是有原因的。从Cloudinary获取新密钥,并尽快删除您发布的密钥。

优秀答案推荐

If you want to use the latest version of Strapi, v.4 and above, you need to change strapi provider package to this one:

如果您想使用最新版本的Strapi v.4及更高版本,则需要将strapi提供程序包更改为以下版本:


npm install @strapi/provider-upload-cloudinary --save

NPM安装@stRapi/提供者-上传-Cloudinary--保存


Then, you need to update your plugins.js file in config/plugins.js to the following ( Be aware that it has a slightly different structure than the previous package - everything is placed in config object, instead of upload like it was on a previous version):

然后,您需要将config/plugins.js中的plugins.js文件更新为以下内容(请注意,它的结构与前一个包的结构略有不同-所有内容都放在配置对象中,而不是像在前一个版本中那样上传):


module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'cloudinary',
providerOptions: {
cloud_name: env('CLOUDINARY_NAME'),
api_key: env('CLOUDINARY_KEY'),
api_secret: env('CLOUDINARY_SECRET'),
},
actionOptions: {
upload: {},
delete: {},
},
},
},
// ...
});


Also, if you are having issues with properly rendering your images on your Strapi dashboard you can update middlewares.js in config/middlewares.js:

此外,如果您在Strapi仪表板上正确呈现图像时遇到问题,您可以在config/midlewares.js中更新midlewares.js:


Instead of 'strapi::security' in module.exports, paste this:

在模块.exports中粘贴以下内容,而不是'strapi::security':


// ...
{
name: 'strapi::security',
config: {
contentSecurityPolicy: {
useDefaults: true,
directives: {
'connect-src': ["'self'", 'https:'],
'img-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
'media-src': ["'self'", 'data:', 'blob:', 'res.cloudinary.com'],
upgradeInsecureRequests: null,
},
},
},
},
// ...


If you do all the configuration in latest version but it won't work, maybe this is the solution. I check the name of file is config/plugins.js not config/plugin.js. This file must have s. LOL

如果你在最新版本中做了所有的配置,但它不起作用,也许这就是解决方案。我检查了一下文件的名称是config/plugins.js,而不是config/plugin.js。这个档案一定有S,哈哈


更多回答

I have the same problem... But my config is up to date with the latest packages... Still doesnt work tho... Does it have something to do with working locally or in production?

我也有同样的问题。但我的配置是最新的包...但还是不管用。这与在当地工作或在生产中工作有关吗?

Never mind, i had "plugin.js" instead of "plugins.js" as a foldername! Its works now.. stupid mistake... 🤷‍♂️

没关系,我的文件夹名称是“plugin.js”而不是“plugins.js”!它现在起作用了..愚蠢的错误..。🤷‍♂️

wow @mikeyfe6 you're a lifesaveer, I have been trying to figure out why the images only uploaded to local. changing the file name to plugins.js worked!

哇@mikeyfe6你真是个救世主,我一直在想为什么这些照片只上传到本地。将文件名更改为plugins.js成功了!

You're welcome(, i think....) 🥲 @GameBoy

不客气(,我想。)🥲GameBoy

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com