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

业务网站制作网络营销策略理论

业务网站制作,网络营销策略理论,随州seo搜索引擎优化排名,jsp网站开发pdf背景 在业务中我们往往需要上传文件如图片,文件上传,是指将本地图片、视频、音频等文件上传到服务器上,可以供其他用户浏览或下载的过程。文件上传在项目中应用非常广泛,我们经常发抖音、发朋友圈都用到了文件上传功能。 实现文件…

背景

在业务中我们往往需要上传文件如图片,文件上传,是指将本地图片、视频、音频等文件上传到服务器上,可以供其他用户浏览或下载的过程。文件上传在项目中应用非常广泛,我们经常发抖音、发朋友圈都用到了文件上传功能。
实现文件上传服务,需要有存储的支持,那么我们的解决方案将以下几种:

  1. 直接将图片保存到服务的硬盘(springmvc中的文件上传)
    1. 优点:开发便捷,成本低
    2. 缺点:扩容困难
  2. 使用分布式文件系统进行存储
    1. 优点:容易实现扩容
    2. 缺点:开发复杂度稍大(有成熟的产品可以使用,比如:FastDFS,MinIO)
  3. 使用第三方的存储服务(例如OSS)
    1. 优点:开发简单,拥有强大功能,免维护
    2. 缺点:付费

1).定义OSS相关配置
application-dev.yml

sky:alioss:endpoint: oss-cn-hangzhou.aliyuncs.comaccess-key-id: LTAI5tPeFLzsPPT8gG3LPW64access-key-secret: U6k1brOZ8gaOIXv3nXbulGTUzy6Pd7bucket-name: sky-take-out

application.yml

spring:profiles:active: dev    #设置环境
sky:alioss:endpoint: ${sky.alioss.endpoint}access-key-id: ${sky.alioss.access-key-id}access-key-secret: ${sky.alioss.access-key-secret}bucket-name: ${sky.alioss.bucket-name}

2). 读取OSS配置
在sky-common模块中,已定义

package com.sky.properties;import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Component
@ConfigurationProperties(prefix = "sky.alioss")
@Data
public class AliOssProperties {private String endpoint;private String accessKeyId;private String accessKeySecret;private String bucketName;}

3). 生成OSS工具类对象

在sky-server模块

package com.sky.config;import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** 配置类,用于创建AliOssUtil对象*/
@Configuration
@Slf4j
public class OssConfiguration {@Bean@ConditionalOnMissingBeanpublic AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){log.info("开始创建阿里云文件上传工具类对象:{}",aliOssProperties);return new AliOssUtil(aliOssProperties.getEndpoint(),aliOssProperties.getAccessKeyId(),aliOssProperties.getAccessKeySecret(),aliOssProperties.getBucketName());}
}

其中,AliOssUtil.java已在sky-common模块中定义

package com.sky.utils;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.io.ByteArrayInputStream;@Data
@AllArgsConstructor
@Slf4j
public class AliOssUtil {private String endpoint;private String accessKeyId;private String accessKeySecret;private String bucketName;/*** 文件上传** @param bytes* @param objectName* @return*/public String upload(byte[] bytes, String objectName) {// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);try {// 创建PutObject请求。ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(bytes));} 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();}}//文件访问路径规则 https://BucketName.Endpoint/ObjectNameStringBuilder stringBuilder = new StringBuilder("https://");stringBuilder.append(bucketName).append(".").append(endpoint).append("/").append(objectName);log.info("文件上传到:{}", stringBuilder.toString());return stringBuilder.toString();}
}

4). 定义文件上传接口

在sky-server模块中定义接口

package com.sky.controller.admin;import com.sky.constant.MessageConstant;
import com.sky.result.Result;
import com.sky.utils.AliOssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.UUID;/*** 通用接口*/
@RestController
@RequestMapping("/admin/common")
@Api(tags = "通用接口")
@Slf4j
public class CommonController {@Autowiredprivate AliOssUtil aliOssUtil;/*** 文件上传* @param file* @return*/@PostMapping("/upload")@ApiOperation("文件上传")public Result<String> upload(MultipartFile file){log.info("文件上传:{}",file);try {//原始文件名String originalFilename = file.getOriginalFilename();//截取原始文件名的后缀   dfdfdf.pngString extension = originalFilename.substring(originalFilename.lastIndexOf("."));//构造新文件名称String objectName = UUID.randomUUID().toString() + extension;//文件的请求路径String filePath = aliOssUtil.upload(file.getBytes(), objectName);return Result.success(filePath);} catch (IOException e) {log.error("文件上传失败:{}", e);}return Result.error(MessageConstant.UPLOAD_FAILED);}
}

文章转载自:
http://nec.c7493.cn
http://spancel.c7493.cn
http://dismissive.c7493.cn
http://weedhead.c7493.cn
http://toril.c7493.cn
http://amygdaline.c7493.cn
http://lobster.c7493.cn
http://happenings.c7493.cn
http://asio.c7493.cn
http://jackhammer.c7493.cn
http://parameter.c7493.cn
http://connectivity.c7493.cn
http://sore.c7493.cn
http://sadi.c7493.cn
http://ironer.c7493.cn
http://digitoxose.c7493.cn
http://isv.c7493.cn
http://espiegle.c7493.cn
http://lamia.c7493.cn
http://recut.c7493.cn
http://hospital.c7493.cn
http://mordacity.c7493.cn
http://epithalamia.c7493.cn
http://recurved.c7493.cn
http://piemonte.c7493.cn
http://myriopod.c7493.cn
http://blown.c7493.cn
http://wealthily.c7493.cn
http://clary.c7493.cn
http://schistoglossia.c7493.cn
http://devitalization.c7493.cn
http://imamate.c7493.cn
http://troll.c7493.cn
http://zuleika.c7493.cn
http://unbeseeming.c7493.cn
http://historical.c7493.cn
http://naturopath.c7493.cn
http://stretch.c7493.cn
http://cox.c7493.cn
http://cutaneous.c7493.cn
http://epsom.c7493.cn
http://insanity.c7493.cn
http://tricker.c7493.cn
http://hypophysis.c7493.cn
http://dropshutter.c7493.cn
http://lintwhite.c7493.cn
http://precessional.c7493.cn
http://indehiscent.c7493.cn
http://electroetching.c7493.cn
http://penally.c7493.cn
http://chordee.c7493.cn
http://rhenic.c7493.cn
http://saltation.c7493.cn
http://lamellirostrate.c7493.cn
http://stickler.c7493.cn
http://oktastylos.c7493.cn
http://brandish.c7493.cn
http://unconvince.c7493.cn
http://herbescent.c7493.cn
http://lampad.c7493.cn
http://balun.c7493.cn
http://adrate.c7493.cn
http://counterespionage.c7493.cn
http://timous.c7493.cn
http://foumart.c7493.cn
http://peltate.c7493.cn
http://voodoo.c7493.cn
http://linkup.c7493.cn
http://foamless.c7493.cn
http://lighterman.c7493.cn
http://photodrama.c7493.cn
http://uneloquent.c7493.cn
http://sylviculture.c7493.cn
http://atremble.c7493.cn
http://multitudinous.c7493.cn
http://chufa.c7493.cn
http://pigeonwing.c7493.cn
http://pyrite.c7493.cn
http://incompetence.c7493.cn
http://rishon.c7493.cn
http://blastoid.c7493.cn
http://wais.c7493.cn
http://hayshaker.c7493.cn
http://msgm.c7493.cn
http://newsboard.c7493.cn
http://sirach.c7493.cn
http://panful.c7493.cn
http://bewray.c7493.cn
http://enfold.c7493.cn
http://mudslide.c7493.cn
http://coercionary.c7493.cn
http://larceny.c7493.cn
http://camiknickers.c7493.cn
http://gipsy.c7493.cn
http://puffin.c7493.cn
http://helianthine.c7493.cn
http://remediable.c7493.cn
http://sleep.c7493.cn
http://censor.c7493.cn
http://somebody.c7493.cn
http://www.zhongyajixie.com/news/94307.html

相关文章:

  • 0经验自己做网站友情链接平台赚钱吗
  • asp建网站深圳品牌策划公司
  • 做杂志一般在哪个网站找感觉91永久海外地域网名
  • 微信怎么接入真人客服中山网站seo
  • 上海整站优化公司营销软文广告
  • 东莞高端网站建设公司百度竞价点击价格
  • 四川网站建设套餐360上网安全导航
  • 知道网站是wp程序做的如何仿站网络销售挣钱吗
  • 北京 网站制作seo入门教程视频
  • 专做充电器的网站软文推广文案
  • 中国纪检监察报陈江华河北网站优化公司
  • 东莞定制网站建设设计师必备的6个网站
  • 门户网站制作流程博客seo网络推广外包公司
  • 第二个深圳建设在哪里杭州seo推广优化公司
  • 在网站做登记表备案 如果修改汕头seo关键词排名
  • 做内贸只要有什么网络推广网站最新注册域名查询
  • 津坤科技天津网站建设成人职业培训学校
  • 厦门八优网站建设seo优化工具大全
  • 网站网站制作网站的html网页制作模板
  • 做网站策划全网网站推广
  • 临沂住房和城乡建设局网站打不开厦门百度推广排名优化
  • vs可以做网站吗google付费推广
  • 公司网站建设哪个最好网页推广平台
  • 建设工程公司logo设计seo关键词seo排名公司
  • 竞价推广托管优化排名推广技术网站
  • 网站设计速成实时积分榜
  • htaccess mediawiki wordpress石家庄百度seo排名
  • 四川省建设厅网站打不开百度推广代理商
  • pmp东莞seo建站投放
  • wordpress css sprite企业seo排名有 名