Self built map bed application, I only recommend serverless

Time:2020-11-19

Serverless can be used for self built network disk, but also can be particularly convenient to build map bed.

Programmers usually write in markdown format. Although markdown is simple and convenient, the insertion of pictures is a problem. At this time, we need to use the drawing bed.

Self built map bed application, I only recommend serverless

What is a picture bed?

Generally speaking, there will be a link to the pictures on the Internet articles after the browser opens. This link points to the “map bed”.

If you want to copy an image, you will occasionally encounter the situation of “no picture quotation”. This is because the map beds of major websites are not allowed to be accessed publicly. At this point, you need to save the image, and then upload and insert again. If you have your own map bed, you don’t have to fiddle with illustrations when you blog.

Effect display

Self built map bed application, I only recommend serverless

First of all, we need to open it firstTencent cloud serverless cloud functionandObject store cosServices;

Next, we can operate directly through the cloud function console or deploy through the serverless framework tool.

1、 Deployment using cloud function console

1. Create a new function and upload the function code package

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

Code package address: https://github.com/awesome-scf/scfimgbed
Note: you can see it directly in the zip package index.js , cannot be in a folder

2. Modify the file configuration

Open “function management – function code” and modify it defaultconfig.js File configuration. After modification, rename the file to config.js 。

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

3. Create object storage cos bucket

If there is no bucket for object storage, you need to create one and obtain the bucket and region information in the bucket overview

Self built map bed application, I only recommend serverless

And create a folder in the bucket:

Self built map bed application, I only recommend serverless

4. Create a new trigger

After modification, click save and create two new triggers in trigger management

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

Through the above four steps, the map bed application is successfully built~

2、 Deploy from the command line

1. Install the server less framework

npm install -g serverless

2. Download the project template code

Enter the function directory page under the template to modify the configuration information

sls init imgbed-for-scf
cd imgbed-for-scf/scf 

In the configuration fileconfig.jsFill in your secretid and secretkey

const config = {
    tencent_cos: {
        Secretid: 'xxxxxxxxx', // your secretid
        Secretkey: 'xxxxxxxxx', // your secret key
    }
}
module.exports = config

You can also use thesls registry imgbed-for-scfInstructions to quickly learn the details of the project.

3. Deployment

Back to the root directory, deploy completes the deployment.

cd ..
sls deploy

4. Test application

After the deployment is successful, open thescfDirectoryupload.htmlFile, will create a successful API gateway URL, fill in SCF_ In the URL field

Self built map bed application, I only recommend serverless

Self built map bed application, I only recommend serverless

After saving, open the page in the browser to use your own map bed application:

Self built map bed application, I only recommend serverless

One More Thing

Experience Tencent cloud serverless demo immediately and get the new server less user Gift Packserverless/start

Welcome to:Chinese version of serverless