Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
preface
- Online music poke me ah!
- Music blog source code online!
- Recently, WHEN I was sorting out my online music (because I changed the server recently), I found that the uploaded picture files were very messy. For example, the music was uploaded to minio (file server), the pictures of IT knowledge module were uploaded to the folder designated by Node, and the files of other modules were in another folder of Node.
- I was thinking if I could manage all these files by one, so I first thought of building a file server in the company (DPF) during my internship, and it was really convenient to use it, which is Minio, the protagonist of today.
- In fact, my own online music has been used for a long time, but I did not say that all files belong to its management, and now the application is deployed on Docker, I do not know why Node file mapping failed, but Minio can map out, this is also the beginning of the original thought of files in Minio.
- The last article called Minio unified management file has the actual code, but seems to be missing something?
- Oh ~ is a little bit less common error processing summary, this, the follow-up to come. There was a real problem with changing servers.
- Are you ready?
Happy holidays again.
Let’s start with a picture.
Minio has an intuitive and visual interface. It is easy to manage, upload and download files, and set permissions and expiration time.
Use for three years, encountered pits
-
It is not possible to copy Linux commands from Win (CVCV).
-
There is a problem with the new version, suggest using miniO/miniO :RELEASE. 2021-06-17t00-10-46z
-
Are MINIO_ACCESS_KEY and MINIO_SECRET_KEY deprecated?
-
PutObject upload the resulting URL and opens it in the browser to download the file instead of showing the image (putObject images cannot load 💔)
1, CV problems?
Minio was deployed as a window on 47 at the beginning. Later, 47 server was changed to docker environment, and Minio was also changed to Docker operation. Later, I migrated it to docker of 39. (Because the server expires)
The process is bumpy, but also because of these “wind and rain”, can see the “rainbow”.
The Docker environment on the 47 server has been half a year ago, when the operation is as follows:
// pull minio/minio // run docker run -p 9000:9000 --name minio -d -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=123456" -v /home/minio:/data -v /home/minio/config:/root/.minio minio/minio server /dataCopy the code
These parameters were discussed in the last Minio unified management file article
Then it’s up and running.
A few days ago from 47 -> 39 server, I also with 47 the same operation, directly pull the brake.
错 : No such file or directory
Don’t panic when you make a mistake. Find someone who has done it before.
Okay, I get it. It’s good to be alone.
So I baidu again, one of them gave me inspiration.
What he means is that scripts developed in Windows need to be formatted differently.
Because of my long docker run minio… The command is copied from the DOS document, directly copy to Linux may have coding problems, so I have a guessing mentality to hand knock again, unexpectedly, unexpectedly really run successfully!
Damn, this is a small hole for lazy CV.
Second, find Minio in memory
Minio successfully ran on docker, access failed just when I was trying to access.
2.1 Discovering Faults
How could it not be accessed? Port mapping, firewall is turned off, access is not allowed, and a strange situation is that I clearly entered 9000 port, but it automatically jumped to 41757 this strange port.
I felt that he could not access 9000, so it automatically jumped to port 41757.
2.2 Try to find the problem
Quickly check the log.
❓ is it possible that the new version is different?
2.3 A little thinking
Because the previous minio was pulled half a year ago, I checked the update record and there was indeed an updated version.
Query minio service version: Docker Search minio
Minio/MiniO :RELEASE. 2021-06-17t00-10-46Z, because there are a lot of bugs in other versions.
Through the above pit, we found that the version of Minio was updated very quickly, and the latest version had changed beyond recognition. I checked the latest official website release version.
More than 200 versions have been released, big and small.
We chose June 17, 2021.
2.4 Practice
If you can find the problem, give it a try.
2.4.1 Pulling a MiniO Image
docker pull minio/minio:RELEASE.2021-06-17T00-10-46Z
Copy the code
Start the 2.4.2
Docker run -p 9000:9000 minio/minio:RELEASE. 2021-06-17T00-10-46z server /data // Or custom account password docker run -p 9000:9000 --name minio -d -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=123456" -v /home/minio:/data -v /home/minio/config:/root/.minio minio/minio:RELEASE.2021-06-17T00-10-46Z server /dataCopy the code
Oh, my god, it’s running!
Sure enough, it is the version of the problem, the version upgrade too fast, fortunately found the old version.
Are MINIO_ACCESS_KEY and MINIO_SECRET_KEY deprecated?
I just wanted to log on to Minio and see how my music files looked.
Authentication failed, check your access credentials are displayed when you log in
I quickly checked the log to see if there were any useful error messages.
Warning :MINIO_ACCESS_KEY and MINIO_SECRET_KEY are deprecated. Use MINIO_ROOT_USER and MINIO_ROOT_PASSWORDCopy the code
When run is said, MINIO_ACCESS_KEY and MINIO_SECRET_KEY are deprecated. The new MINIO_ROOT_USER and MINIO_ROOT_PASSWORD are used to set the account password.
So I stopped my minio service and decided to switch to the run command.
New command:
docker run -p 9000:9000 --name minio -d
-e "MINIO_ROOT_USER=admin"
-e "MINIO_ROOT_PASSWORD=123456"
-v /home/minio:/data
-v /home/minio/config:/root/.minio
minio/minio:RELEASE.2021-06-17T00-10-46Z server /data
Copy the code
But when I ran with the new command, I reported another error.
‘server’ is not a minio sub-command. See ‘minio –help’
This is displayed when you run a minio command with parameters that are not minio commands.
MINIO_ACCESS_KEY and MINIO_SECRET_KEY are deprecated. The new MINIO_ROOT_USER and MINIO_ROOT_PASSWORD are used to set account passwords.
It’s not a new minio command parameter.
After checking, I could not find any other solution, so I thought that 2.4.2 Startup was also a simple way to start the minio service.
docker run -p 9000:9000 minio/minio:RELEASE.2021-06-17T00-10-46Z server /data
Copy the code
Then it started successfully, so I reran the previous command.
docker run -p 9000:9000 --name minio -d -e "MINIO_ACCESS_KEY=admin" -e "MINIO_SECRET_KEY=123456" -v /home/minio:/data -v /home/minio/config:/root/.minio minio/minio:RELEASE.2021-06-17T00-10-46Z server /dataCopy the code
MINIO_ACCESS_KEY and MINIO_SECRET_KEY are deprecated.
Nginx has set resource caching, so the browser can cache resources (30 days).
From disk cache, the music module will not load images if minio service has problems.
Another problem is that the miniO management interface cannot be logged in (an error occurs), but resources can still be accessed, indicating that the service is not suspended.
4. PutObject images cannot be loaded 💔
4.1 Discovering Faults
In particular, the putObject method in JavaScript, while I was using minio’s method in KOA2 to upload a file, I found that the front-end fetch link did not display properly after the file was uploaded.
4.2 Check official examples
First post the method description of minio.
Let’s see how this is called in real code.
Use the official sample code directly.
var Fs = require('fs')
var file = '/tmp/40mbfile'
var fileStream = Fs.createReadStream(file)
var fileStat = Fs.stat(file, function(err, stats) {
if (err) {
return console.log(err)
}
minioClient.putObject('mybucket'.'40mbfile', fileStream, stats.size, function(err, objInfo) {
if(err) {
return console.log(err) // err should be null
}
console.log("Success", objInfo)
})
})
Copy the code
The image uploaded successfully, the official website example did not disappoint me, so I naturally returned to the front image URL display.
Found but can’t show?
Check, the original link did not write port number, careless ah.
And when you add that, it still doesn’t work, right?
4.3 Images uploaded by JavaScript are different from other image ICONS
Open the Minio admin interface to make sure it is added.
❓ how can I upload 875.jpg and other pictures are different?
🙋 Other pictures that are not gray are manually uploaded by clicking the plus sign.
4.4 Copy how Java is written (have written before, sure successful)
Upload your music module via KOA2 is gray, a flash of inspiration, before Java wrote code to upload music module putObject method, go to see how Java write.
The Java code is as follows:
MinioUtils.putObject(
singerSong.getBucketName(),
objectName,
file.getInputStream(),
file.getSize(),
file.getContentType()
);
Copy the code
The JavaScript above looks like this:
minioClient.putObject(
'mybucket'.'40mbfile',
fileStream,
stats.size
)
Copy the code
The minio management interface does not display the file type, because I did not write it.
Did I miss something? One more tour of the official website.
T aim, my code is copied from the official website example. The example does not pass file types.
You can only start with the metaData parameter on the official website, which may be the file type.
However, DO not know what metadata is, the official website did not say, how to pass, a little pit.
🙋 Find a way to solve the problem.
4.5 Less passing the ContentType parameter?
The method has been changed but the official website has not been changed, so he said to pass the ContentType parameter as much as possible.
So I also went to look at putObject source:
I don’t see the ContentType argument I want to see.
4.6 Change the source code?
Good guy, someone says to change the source code directly, it is a way indeed, but this is forced to choose the inferior policy, look for it again.
4.7 What does the official example say?
Minio github has also discovered this problem, saying that it can be solved by sending multiple content-Types. I also know how to send multiple content-types.
Don’t say.
Anyway, I didn’t set the file type, put the URL in the browser, it will download directly, if the type is correct, it will preview, it won’t download for you.
4.8 Metadata parameters are explained
Until I read this. It doesn’t matter what you say, it matters that metaData is being used.
My code modification is as follows:
var Fs = require('fs') var file = '/tmp/40mbfile' var fileStream = Fs.createReadStream(file) var fileStat = Fs.stat(file, function(err, stats) { if (err) { return console.log(err) } minioClient.putObject( 'mybucket', '40mbfile', fileStream, stats.size, {'Content-Type': Type}, // This type is uploaded from the front end of the file object can get function(err, objInfo) { if(err) { return console.log(err) // err should be null } console.log("Success", objInfo) }) })Copy the code
Successful, the front end is displayed correctly, and the Minio management interface displays the image type icon correctly.
The last
No rain, no rainbow.
Refactoring, there will always be gains, there will be growth, online music hopefully better and better, will continue to update until the dry no longer.
I remember when I was practicing in the company, my senior fellow from the same school told me: CVCV is not recommended for code, and I will remember it only when I play it with multiple hands. In the process of using miniO, I have problems with CV. , have a deep understanding of the future development will deliberately hand.
Is it really the most stable version when you upload to the Master stable version? Ah, minio. (2) Looking for Minio in memory
The actual combat also know the importance of the cache, if the program collapsed, the browser also set a 30 day cache time, will not immediately give customers visual hatred, of course, forced refresh when I did not say 😁. Is MINIO_ACCESS_KEY and MINIO_SECRET_KEY deprecated?
The existence of the problem is not terrible, terrible is that you really seriously checked the problem, do not change the source code, will be the way we use it is wrong. PutObject image cannot be loaded.
If it helps, your likes are my lubricant.
Related literature
Docker-minio installation is used
Docker installs Minio and fills the latest version of the pit
Heroku: deploying minio server with Dockerfile CMD failure
[BUG] Content-Type #129 is not set when uploading to minio
Images uploaded through the miniO interface cannot be previewed on the management interface. Images uploaded directly on the management interface can be previewed
VUE cannot directly upload files to MinIO, prompting _fs.default.stat is not a function?
In the past to recommend
Minio unified management files (real JS, JAVA)
Especially big said my code all do not add semicolons
Lao Shi said that everything is the object, you also believe?
Vue-cli3 builds the component library
Vue implements dynamic routing (and the interviewer blows project highlights)
Axios manipulation in a project you didn’t know about (Core principles of handwriting, compatibility)
VuePress builds project component documentation
Vue koa2 + + nginx deployment
Vue-typescript-admin-template background management system
The original link
Juejin. Cn/post / 701515…