当前位置: 首页 > wzjs >正文

开发手机端网站模板下载要找做冲压件的厂去哪个网站找

开发手机端网站模板下载,要找做冲压件的厂去哪个网站找,wordpress文章编缉,做建材去什么网站目录 对象存储背景 阿里云OSS 对象存储背景 单节点环境下,文件往往存储在tomcat服务器内,随着业务需求的增多,单节点已不能满足需求,项目架构需要扩展到多节点(见下图),此时文…

目录

对象存储背景        

阿里云OSS


对象存储背景        

        单节点环境下,文件往往存储在tomcat服务器内,随着业务需求的增多,单节点已不能满足需求,项目架构需要扩展到多节点(见下图),此时文件经过nginx转发存储到某一个节点,在分布式架构下对文件的访问就存在问题(文件存储到节点A,查看文件请求到节点B访问不了文件)。

        在分布式环境下,需要引入集中管理文件的节点服务,改进如下:

        分布式文件服务解决方案有很多,常见的有:独立搭建文件服务器,如基于开源FastDFS搭建;引入第三方云储存方案,如基于阿里云的OSS;相比独立搭建文件服务器,云存储方案有诸多优势:SDK使用简单、运维成本低、图形化的管理控制台、提供强大的文件处理功能、CDN加速、服务扩展简单等,本文重点讲述基于阿里云的OSS方案。

阿里云OSS

        使用步骤如下:

        1、【阿里云官网】开通OSS服务

        2、【阿里云官网】创建Bucket

        重点关注标签有:Bucket 名称、Endpoint,本文新建的Bucket 名称 = gingko-sawyer,Endpoint = oss-cn-beijing.aliyuncs.com

        3、【阿里云官网】创建并使用RAM账号进行API访问或日常运维,请登录RAM控制台创建RAM账号,创建AccessKey,并将AccessKeyId和AccessKeySecret设置到本地电脑环境变量中。

        4、后台编写代码实现基于阿里云OSS文件上传及下载

        4.1、添加aliyun.oss依赖

<dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.17.4</version>
</dependency>

        4.2、修改配置,增加对oss的支持

server:port: 8080
#aliyun oss config
aliyun:oss:endpoint: oss-cn-beijing.aliyuncs.comregion: cn-beijingbucket-name: gingko-sawyerfoler-prefix: oss/host: https://gingko-sawyer.oss-cn-beijing.aliyuncs.com

        4.3 文件上传&下载程序

package com.ginko.aliyunoss.controller;import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.Protocol;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.InputStream;@RestController
@RequestMapping("oss")
@Slf4j
public class OSSController {@Value("${aliyun.oss.endpoint}")private String endpoint;@Value("${aliyun.oss.region}")private String region;@Value("${aliyun.oss.bucket-name}")private String bucketName;@Value("${aliyun.oss.foler-prefix}")private String folerPrefix;//上传到oss中具体的文件夹目录@Value("${aliyun.oss.host}")private String host;@PostMapping("/upload")public String upload(@RequestParam("file") MultipartFile file) throws Exception {// 创建 ClientBuilderConfiguration 实例,用于配置 OSS 客户端参数ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();// 设置签名算法版本为 V4clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);// 设置使用 HTTPS 协议访问 OSS,保证传输安全性clientBuilderConfiguration.setProtocol(Protocol.HTTPS);// 创建 OSS 客户端实例OSS ossClient = OSSClientBuilder.create()// endpoint.endpoint(this.endpoint)// 从环境变量中获取访问凭证(需提前配置 OSS_ACCESS_KEY_ID 和 OSS_ACCESS_KEY_SECRET).credentialsProvider(CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider())// 设置客户端配置.clientConfiguration(clientBuilderConfiguration)// 设置region.region(this.region).build();try {// 填写Bucket名称String bucketName = this.bucketName;// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。String objectName = this.folerPrefix + file.getOriginalFilename();InputStream inputStream = file.getInputStream();// 创建PutObjectRequest对象。PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);// 创建PutObject请求。PutObjectResult result = ossClient.putObject(putObjectRequest);System.out.println(result);} finally {// 当OSSClient实例不再使用时,调用shutdown方法以释放资源ossClient.shutdown();}return "success";}@PostMapping("/download")public String download() throws Exception {// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。String endpoint = this.endpoint;//从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();// 填写Bucket名称,例如examplebucket。String bucketName = this.bucketName;// 填写不包含Bucket名称在内的Object完整路径,例如testfolder/exampleobject.txt。String objectName = this.folerPrefix + "1.png";// 填写Object下载到本地的完整路径。String pathName = "D:\\rename.png";// 填写Bucket所在地域。以华东1(杭州)为例,Region填写为cn-hangzhou。String region = this.region;// 创建OSSClient实例。// 当OSSClient实例不再使用时,调用shutdown方法以释放资源。ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);OSS ossClient = OSSClientBuilder.create().endpoint(endpoint).credentialsProvider(credentialsProvider).clientConfiguration(clientBuilderConfiguration).region(region).build();try {// 下载Object到本地文件,并保存到指定的本地路径中。如果指定的本地文件存在会覆盖,不存在则新建。// 如果未指定本地路径,则下载后的文件默认保存到示例程序所属项目对应本地路径中。ObjectMetadata object = ossClient.getObject(new GetObjectRequest(bucketName, objectName), new File(pathName));} catch (OSSException oe) {System.out.println("Caught an OSSException, which means your request made it to OSS, "+ "but was rejected with an error response for some reason.");System.out.println("Error Message:" + oe.getErrorMessage());System.out.println("Error Code:" + oe.getErrorCode());System.out.println("Request ID:" + oe.getRequestId());System.out.println("Host ID:" + oe.getHostId());} catch (ClientException ce) {System.out.println("Caught an ClientException, which means the client encountered "+ "a serious internal problem while trying to communicate with OSS, "+ "such as not being able to access the network.");System.out.println("Error Message:" + ce.getMessage());} finally {if (ossClient != null) {ossClient.shutdown();}}return "success";}
}

        5、测试,通过postman模拟上传及下载文件

        如下图所示,1.png文件已经被上传到oss中,rename.png是从oss下载到本地的文件


文章转载自:

http://XjSUgIUB.qwrqg.cn
http://t8rO6T1s.qwrqg.cn
http://bVVxFFsW.qwrqg.cn
http://oiFQjaOE.qwrqg.cn
http://JOB20JJo.qwrqg.cn
http://sUyroi3A.qwrqg.cn
http://nGqa2POe.qwrqg.cn
http://eK7YCF0l.qwrqg.cn
http://qa2mVnOd.qwrqg.cn
http://5ZBlDPai.qwrqg.cn
http://jwiGzsU0.qwrqg.cn
http://gWoomQKb.qwrqg.cn
http://4iovFWjM.qwrqg.cn
http://BYVHAvHT.qwrqg.cn
http://fzyN8SlJ.qwrqg.cn
http://hsPJA1bI.qwrqg.cn
http://1GEH4jpt.qwrqg.cn
http://n09nzIin.qwrqg.cn
http://kkkehWW7.qwrqg.cn
http://mJVZENKt.qwrqg.cn
http://Rk8kFNdQ.qwrqg.cn
http://rAA9QfpX.qwrqg.cn
http://4Kh64XqY.qwrqg.cn
http://TNhwCl4w.qwrqg.cn
http://0jYmMKkU.qwrqg.cn
http://4JxZjY8T.qwrqg.cn
http://cjMEcTlI.qwrqg.cn
http://1mTHiNwb.qwrqg.cn
http://d9t9aoFl.qwrqg.cn
http://htbjIAvP.qwrqg.cn
http://www.dtcms.com/wzjs/634229.html

相关文章:

  • 做信息安全的网站微信 wordpress
  • 设计得好的网站推荐网站排名怎么优化
  • 开江建设局网站柳州网站建设柳州
  • 洛阳网站建设招聘信息wordpress侧边栏导航
  • 网站开发公司起名seo每天一贴博客
  • 有经验的武进网站建设网站宣传活动怎么做
  • 茶叶外贸网站建设网站留言板怎么做phpsql
  • 濮阳哪里做网站wordpress网站mip改造
  • 网站建设公司咨询宁波网站模板哪家性价比高
  • 成都网站建设哪家比较好网站报价书
  • jsp网站seo优化石狮网站定制
  • 网站的建设进入哪个科目wordpress留学主题
  • 电子商务知名网站一流的五屏网站建设
  • 重庆制作网站软件做类似淘宝的网站开发需要什么
  • 零售网站开发云南app制作
  • 专业网站建设技术创建一个网站买卖
  • 网站建设公司那记号网站开发使用哪些开发语言
  • 唱片公司网站模板wordpress换php7出错
  • 律师事务所公司类网站建设案例一级a做爰电影免费观看网站
  • 访问不了服务器网站吗北京工商登记
  • 网站建设管理自查报告网站有哪些推荐
  • 灯具网站建设尚层别墅装饰公司官网
  • 做网站主流用什么语言网络营销的特点包括哪些
  • 网站流量分析报告建设部网站业绩补录
  • 制作网站的手机软件wordpress图片评论
  • 账号注册网站杭州网站建设路
  • 网站空间可以通过什么获取建设网站是什么意思
  • 服务器网站建设软件有哪些说明多媒体教学网站开发的一般步骤
  • 法治建设网站模块名称平面设计培训班价格
  • 苏州找工作网站有哪些微信上的h5页面是怎么制作的