hezzze / strapi-provider-upload-oss Goto Github PK
View Code? Open in Web Editor NEWA provider for strapi server to upload file to Aliyun OSS
License: MIT License
A provider for strapi server to upload file to Aliyun OSS
License: MIT License
oss文件访问权限控制无法变更,导致上传到私有桶的文件无法访问,复杂场景需要在默认是私有桶下操作,自定义设置ACL权限,建议新增配置项是否是私有桶配置。
参考官方文档:
https://help.aliyun.com/zh/oss/developer-reference/manage-the-acl-of-an-object-2?spm=a2c4g.11186623.0.0.336e22dec03nIX
上传文件的时候变更文件权限为公共读
const oss = require('ali-oss');
const client = oss({
// yourregion填写Bucket所在地域。以华东1(杭州)为例,Region填写为oss-cn-hangzhou。
region: 'yourregion',
// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
accessKeyId: process.env.OSS_ACCESS_KEY_ID,
accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
// yourbucketname填写存储空间名称。
bucket: 'yourbucketname'
});
async function setACL() {
try {
// yourObjectName填写不包含Bucket名称在内的Object的完整路径。
await client.putACL('yourObjectName', 'public-read');
console.log('Set ACL successfully');
} catch (e) {
console.error(e);
}
}
setACL();
In Strapi v3.0.2, the provider interface does not appear when accessing the specified path:
http://your-strapi-server/admin/plugins/upload/configurations/development
Hello,
as I deployed the admin panel to another server according to the doc, the image URLs become https://backend.com//OSS_BASE_URL/xxxx.jpg.
They instantly become normal after deactivation of the plugin. (https://backend.com/uploads/xxxx.jpg)
Woud you please check out the issue?
debug
[2020-12-18T02:30:55.232Z] debug POST /upload (315 ms) 500
[2020-12-18T02:31:16.181Z] debug >>>>>>> upload oss <<<<<<<
[2020-12-18T02:31:16.194Z] debug undefined
[2020-12-18T02:31:16.280Z] error SignatureDoesNotMatchError: The request signature we calculated does not match the signature you provided. Check your key and signing method.
目录结构
When I upload an image in Media Library, the plugin generates multiple thumbnails.
I read the code only mp4 can generate thumbnails. That's wired, hope some help.
[2020-07-15T14:00:01.653Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:01.684Z] debug undefined
[2020-07-15T14:00:02.042Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.042Z] debug undefined
[2020-07-15T14:00:02.135Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.137Z] debug undefined
[2020-07-15T14:00:02.183Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.183Z] debug undefined
[2020-07-15T14:00:02.514Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.531Z] debug undefined
[2020-07-15T14:00:02.620Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.620Z] debug undefined
[2020-07-15T14:00:02.620Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.633Z] debug undefined
[2020-07-15T14:00:02.718Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.718Z] debug undefined
[2020-07-15T14:00:02.718Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.726Z] debug undefined
[2020-07-15T14:00:02.779Z] debug >>>>>>> upload oss <<<<<<<
[2020-07-15T14:00:02.779Z] debug undefined
[2020-07-15T14:00:02.988Z] debug POST /upload (1672 ms) 200
[2020-07-15T14:00:03.352Z] debug GET /upload/files/count? (40 ms) 200
-provider: 'aliyun-oss',
+provider: 'oss',
原来的数据会怎样?
目前按照文档上的要求写好 ./config/plugins.js 文件后启动应用, 在控制台的 General > Plugins 里看不到已加载的阿里云 OSS 上传插件. 必须要手动上传一次才知道插件已经加载好了.
Hi hezzze,
I want to know what's the recommended policy configuration for the OSS user/role?
I setup the plugin but it can not upload file somehow. No idea if it was due to policy configuration, but even after I grant the AliyunOSSFullAccess
to the user, I still can not upload any files...
stack: Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17)
>>>>>>> upload oss <<<<<<<
Error [ResponseError]: read ECONNRESET, PUT https://my-app.cn-chengdu.aliyuncs.com/dev/uploads/small__cb97850d1a.jpeg -1 (connected: true, keepalive socket: false, agent status: {"createSocketCount":10,"createSocketErrorCount":0,"closeSocketCount":9,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"my-app.cn-chengdu.aliyuncs.com:443:::::::::::::::::::::":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
at Client.requestError (/Users/my-name/workspace/my-app-api/node_modules/ali-oss/lib/client.js:329:13)
at Client.request (/Users/my-name/workspace/my-app-api/node_modules/ali-oss/lib/client.js:216:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async proto.request (/Users/my-name/workspace/my-app-api/node_modules/ali-oss/lib/client.js:194:12)
at async Client.putStream (/Users/my-name/workspace/my-app-api/node_modules/ali-oss/lib/object.js:152:18)
at async Client.put (/Users/my-name/workspace/my-app-api/node_modules/ali-oss/lib/object.js:88:12) {
status: -1,
code: 'ResponseError'
}
[2023-10-11 21:37:15.046] error: read ECONNRESET, PUT https://my-app.cn-chengdu.aliyuncs.com/dev/uploads/_cb97850d1a.jpeg -1 (connected: true, keepalive socket: false, agent status: {"createSocketCount":6,"createSocketErrorCount":0,"closeSocketCount":5,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"my-app.cn-chengdu.aliyuncs.com:443:::::::::::::::::::::":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
ResponseError: read ECONNRESET, PUT https://my-app.cn-chengdu.aliyuncs.com/dev/uploads/_cb97850d1a.jpeg -1 (connected: true, keepalive socket: false, agent status: {"createSocketCount":6,"createSocketErrorCount":0,"closeSocketCount":5,"errorSocketCount":0,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"my-app.cn-chengdu.aliyuncs.com:443:::::::::::::::::::::":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)
headers: {}
at Client.requestError (/Users/leidong/workspace/neighborhood-api/node_modules/ali-oss/lib/client.js:329:13)
at Client.request (/Users/leidong/workspace/neighborhood-api/node_modules/ali-oss/lib/client.js:216:22)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async proto.request (/Users/leidong/workspace/neighborhood-api/node_modules/ali-oss/lib/client.js:194:12)
at async Client.putStream (/Users/leidong/workspace/neighborhood-api/node_modules/ali-oss/lib/object.js:152:18)
at async Client.put (/Users/leidong/workspace/neighborhood-api/node_modules/ali-oss/lib/object.js:88:12)
http-errors deprecated non-error status code; use only 4xx or 5xx status codes node_modules/@strapi/strapi/lib/services/errors.js:64:21
Steps:
npm install strapi-provider-upload-oss --save
in the strapi root folderstrapi develop
[2020-07-12T10:32:57.429Z] error Bootstrap function in plugin "upload" failed
[2020-07-12T10:32:57.429Z] error Error: The provider package isn't installed. Please run
npm install strapi-provider-upload-oss``
do I need to input configs directly in the plugins.js or there is an admin panel to config?
Strapi package.json :
"knex": "<0.20.0",
"sqlite3": "latest",
"strapi": "3.0.5",
"strapi-admin": "3.0.5",
"strapi-connector-bookshelf": "3.0.5",
"strapi-plugin-content-manager": "3.0.5",
"strapi-plugin-content-type-builder": "3.0.5",
"strapi-plugin-email": "3.0.5",
"strapi-plugin-graphql": "3.0.5",
"strapi-plugin-upload": "3.0.5",
"strapi-plugin-users-permissions": "3.0.5",
"strapi-provider-upload-oss": "^0.1.5",
"strapi-utils": "3.0.5"
Many thanks
Strapi v3.6.2
安装成功了,也配置了config/plugins.js
但启动后没有什么变化的?
重新打包了也不行
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.