当前位置:网站首页>Alibaba cloud OSS uploads pictures under folders and encounters pits
Alibaba cloud OSS uploads pictures under folders and encounters pits
2022-07-24 08:13:00 【Sock is a dog】
First of all, I want a script that can upload pictures
The requirement is to have a folder , Unknown picture file
Combined with the official API,https://help.aliyun.com/document_detail/111265.html
nodejs The code is as follows :
// Get pictures from the project
var fs = require('fs');// Reference file system module
var image = require("imageinfo"); // quote imageinfo modular
const OSS = require('ali-oss')
const path = require("path")
const client = new OSS({
// yourregion Fill in Bucket Location . East China 1( Hangzhou ) For example ,Region Fill in for oss-cn-hangzhou.
region: 'oss-cn-beijing',
// Alicloud account AccessKey Have all the API Access rights of , The risk is high . It is highly recommended that you create and use it RAM The user carries out API Visit or daily operations , Please log in RAM Console creation RAM user .
accessKeyId: '--',
accessKeySecret: '--',
// Fill in Bucket name .
bucket: '--',
});
async function put (filename) {
try {
// Fill in OSS The full path of the file and the full path of the local file .OSS The file full path cannot contain Bucket name .
// If the local path is not specified in the full path of the local file , By default, the file is uploaded from the local path corresponding to the project to which the sample program belongs .
const result = await client.put(filename, path.normalize('/data/ueditor-node/example/public/img/ueditor/'+filename), {
headers: {
'Content-Type': 'image/jpg'
}
});
console.log(result);
} catch (e) {
console.log(e);
}
}
function readFileList(path, filesList) {
var files = fs.readdirSync(path);
files.forEach(function (itm, index) {
var stat = fs.statSync(path + itm);
if (stat.isDirectory()) {
// Read files recursively
readFileList(path + itm + "/", filesList)
} else {
var obj = {
};// Define the path and name of an object to hold the file
obj.path = path;// route
obj.filename = itm// name
filesList.push(obj);
}
})
}
var getFiles = {
// Get all the files in the folder
getFileList: function (path) {
var filesList = [];
readFileList(path, filesList);
return filesList;
},
// Get all the pictures in the folder
getImageFiles: function (path) {
var imageList = [];
this.getFileList(path).forEach((item) => {
var ms = image(fs.readFileSync(item.path + item.filename));
ms.mimeType && (imageList.push(item.filename))
});
return imageList;
}
};
// Get all the files in the folder
getFiles.getFileList("./public/img/ueditor/").forEach((e)=>{
put(e.filename)
});
The idea is to get all the picture names under the specified folder first , Then traverse the read , Then upload ,
Then there was the problem
It's probably the same problem
https://github.com/ali-sdk/ali-oss/issues/107
Finally found out ossutil Supported by Windows、Linux and macOS The system manages OSS data .
Perfect solution .
边栏推荐
- Recognition and storage of Graphs
- *Yolo5 learning * data experiment based on yolo5 face combined with attention model CBAM
- Perceptron and multilayer neural network, back propagation and computational graph
- Kotlin higher order function & DSL layout persuasion Guide
- EZDML逆向工程导入数据库分析实操教程
- 图新地球:Revit建模的rvt格式BIM模型如何带着纹理精准匹配地图
- Database system - Basic Concepts
- Upload and insert the execle table into the database based on ThinkPHP
- Intelligent robots and intelligent systems (Professor Zheng Zheng of Dalian University of Technology) -- 1. robots and mobile robots
- Common DOS commands
猜你喜欢

rbm 对比散度

Generative model and discriminant model

*Code understanding * common function parsing in pytoch

Intelligent robots and intelligent systems (Professor Zheng Zheng of Dalian University of Technology) -- 1. robots and mobile robots

Decision tree - ID3, C4.5, cart

图新地球:Revit建模的rvt格式BIM模型如何带着纹理精准匹配地图
![[interview] Why do you need foreach with the for cycle?](/img/f1/3e2b933b91436849eaeb3812c41679.png)
[interview] Why do you need foreach with the for cycle?

我在微软的这六个月

About the big hole of wechat applet promise

Do you want to have a robot that can make cartoon avatars in three steps?
随机推荐
Image feature Harris corner detection
Continuous learning, lifelong learning, episodic memory, memory module paper summary -- gradient episodic memory promotes continuous learning
Autojs article proficient in detailed explanation of autojs script tutorial
Image feature SIFT (scale invariant feature transform)
When does MySQL use table locks and row locks?
Poj3278 catch the cow
[database] complete SQL statement
Wechat applet host environment, applet architecture, concise operation structure
As skillfully uses idea annotation to improve collaboration / development efficiency
Kotlin higher order function & DSL layout persuasion Guide
[matlab] (IV) application of MATLAB in linear algebra
Have you seen the interview questions of VR major? Trust me, it's absolutely useful
News topic classification task -- tochtext library for text classification
jmeter中JSON提取器使用
Thesis reading: geotransformer
FPGA integrated project - image edge detection system
[multithreading] five communication modes between multithreads
图的认识与存储
Common DOS commands
Decision tree - ID3, C4.5, cart