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

网站备案号是什么百度推广需要什么条件

网站备案号是什么,百度推广需要什么条件,绑米wordpress,网站建设课程考核方案SpringBoot整合OSS实现文件上传 以前,文件上传到本地(服务器,磁盘),文件多,大,会影响服务器性能 如何解决? 使用文件服务器单独存储这些文件,例如商业版–>七牛云存储,阿里云OSS,腾讯云cos等等 也可以自己搭建文件服务器(FastDFS,minio) 0 过程中需要实名认证 … 1 开…

SpringBoot整合OSS实现文件上传

以前,文件上传到本地(服务器,磁盘),文件多,大,会影响服务器性能

如何解决? 使用文件服务器单独存储这些文件,例如商业版–>七牛云存储,阿里云OSS,腾讯云cos等等

也可以自己搭建文件服务器(FastDFS,minio)

0 过程中需要实名认证

1 开通阿里云OSS

image-20240719152009607

2 创建bucket

image-20240719152243439

其他不用管,直接完成即可

3 获取AccessKeyId、AccessKeySecret

image-20240719152336136

image-20240719152737253

墙裂建议,保存好此文件,因为后续无法再查看,只能删除重建

4 获取外网访问域名

image-20240719153351723

Endpoint(地域节点): xxxxx

Bucket 域名 : xxxxx

5 创建文件夹

image-20240719153550710

oss中存储在app/upload下

6 添加依赖

  		<!-- 阿里云OSS--><dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.10.2</version></dependency><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.1</version></dependency>

7 封装常量类

根据自己实际情况改变

public class AliyunOSSConstants {// OSS唯一keypublic static final String ASSCESS_KEY_ID = "你的ASSCESS_KEY_ID";// OSS唯一key秘钥public static final String ASSCESS_KEY_SECRET = "你的ASSCESS_KEY_SECRET";// 地域节点public static final String END_POINT = "你的地域节点";// Bucket名称public static final String BUCKET_NAME = "你的Bucket名称";// 文件一级路径public static final String FILE_DIR = "oss中创建的文件路径";// 文件访问域名public static final String COMMON_URL = "这个是后续访问的公共路径前缀";}

8 封装工具类

package com.qf.util;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.CannedAccessControlList;
import com.aliyun.oss.model.CreateBucketRequest;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import org.springframework.web.multipart.MultipartFile;import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;/*** --- 天道酬勤 ---** @author QiuShiju* @date 2024/12/08* @desc*/
public class AliyunOSSUtil {/*** 上传文件*/public static String upLoad(MultipartFile file) {System.out.println("------OSS文件上传开始--------" );String endPoint = AliyunOSSConstants.END_POINT;String accessKeyId = AliyunOSSConstants.ASSCESS_KEY_ID;String accessKeySecret = AliyunOSSConstants.ASSCESS_KEY_SECRET;String bucketName = AliyunOSSConstants.BUCKET_NAME;String fileDir = AliyunOSSConstants.FILE_DIR;SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");String dateStr = format.format(new Date( ));String fileUrl = null;OSS client = new OSSClientBuilder( ).build(endPoint, accessKeyId, accessKeySecret);try {// 判断容器是否存在,不存在就创建if (!client.doesBucketExist(bucketName)) {client.createBucket(bucketName);CreateBucketRequest createBucketRequest = new CreateBucketRequest(bucketName);createBucketRequest.setCannedACL(CannedAccessControlList.PublicRead);client.createBucket(createBucketRequest);}String originalFilename = file.getOriginalFilename( );String suffix = originalFilename.substring(originalFilename.indexOf("."));// 设置文件路径和名称fileUrl = fileDir + "/" + (dateStr + "/" + UUID.randomUUID( ).toString( ).replace("-", "") + suffix);System.out.println("fileUrl:" + fileUrl);// 上传文件PutObjectResult result = client.putObject(new PutObjectRequest(bucketName, fileUrl, file.getInputStream( )));// 设置权限(公开读)client.setBucketAcl(bucketName, CannedAccessControlList.PublicRead);if (result != null) {System.out.println("resp:" + result);System.out.println("------OSS文件上传成功------" + AliyunOSSConstants.COMMON_URL + fileUrl);}} catch (OSSException oe) {oe.printStackTrace();} catch (ClientException ce) {ce.printStackTrace();} catch (IOException e) {e.printStackTrace( );} finally {if (client != null) {client.shutdown( );}}return AliyunOSSConstants.COMMON_URL + fileUrl;}/*** 删除文件*/public static String delete(String fileUrl) {System.out.println("------OSS文件删除开始--------" + fileUrl);String endPoint = AliyunOSSConstants.END_POINT;String accessKeyId = AliyunOSSConstants.ASSCESS_KEY_ID;String accessKeySecret = AliyunOSSConstants.ASSCESS_KEY_SECRET;String bucketName = AliyunOSSConstants.BUCKET_NAME;OSS client = new OSSClientBuilder( ).build(endPoint, accessKeyId, accessKeySecret);try {client.deleteObject(bucketName, fileUrl);System.out.println("------OSS文件删除成功------" + AliyunOSSConstants.COMMON_URL + fileUrl);} catch (OSSException oe) {oe.printStackTrace();} catch (ClientException ce) {ce.printStackTrace();} finally {if (client != null) {client.shutdown( );}}return AliyunOSSConstants.COMMON_URL + fileUrl;}
}

9 接口测试

@RestController
public class UploadController {/*** 演示上传文件到OSS*/@PostMapping("/upload")public R upload(MultipartFile file){String filePath = AliyunOSSUtil.upLoad(file);return R.ok(filePath);}}

10 前端

<template><div><h2>文件上传</h2><!--:http-request="uploadFile"  是用来覆盖默认的action的请求路径的action=""不能删除,因为是<el-upload>组件必填参数,不填会报错-->  <el-uploadclass="upload-demo"dragaction="":http-request="uploadFile"  :on-change="handleChange"multiple><i class="el-icon-upload"></i><div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div></el-upload><div><!-- 上传后展现图片的地方 -->  <img :src="fileSrc" width="200px"></div></div></template><script>
import {uploadPicture} from '@/api/upload'
export default {data(){return{file:null,fileSrc:null}},methods:{handleChange(file){this.file = file.raw;},uploadFile(){const file = this.file;// FormData是js对象,用于存储表单数据  const formData = new FormData();formData.append("file", file); // 由后端接口决定,后端参数叫fileuploadPicture(formData).then((res) => {this.$message({message: "上传成功",type: "success",});this.fileSrc = res.dataconsole.log("fileSrc",this.fileSrc)});}}
}
</script><style scoped lang="scss"></style>

使用:http-request指定文件上传的函数,原有的action、:before-upload、:on-success等不起作用。但删去action可能有报错,所以还是写了action=“”。

uploadPicture()是封装的函数,在upload.js中

import request from '@/utils/request'export function uploadPicture(data) {return request({url: '/upload',method: 'post',data})
}

11 测试即可

image-20240719162138204

12. 后续,需要改造后端

现在只是上传成功

还需要将上传好的图片地址存储到数据库,后续查询时查出地址,在前端展现

提示: 数据库存储图片地址时不要太长,可以只存储重要信息. 公共部分可以等从数据库查询出后再拼接展现给前端

image-20241204104005570


文章转载自:
http://oviparity.c7500.cn
http://entrecote.c7500.cn
http://enspirit.c7500.cn
http://psychochemistry.c7500.cn
http://dissident.c7500.cn
http://morbifical.c7500.cn
http://mithridatize.c7500.cn
http://by.c7500.cn
http://computerite.c7500.cn
http://rasta.c7500.cn
http://nervous.c7500.cn
http://ablate.c7500.cn
http://scolex.c7500.cn
http://inaesthetic.c7500.cn
http://supervoltage.c7500.cn
http://mohair.c7500.cn
http://boiler.c7500.cn
http://proteide.c7500.cn
http://byelaw.c7500.cn
http://stepdame.c7500.cn
http://distaffer.c7500.cn
http://imput.c7500.cn
http://reverberative.c7500.cn
http://unbleached.c7500.cn
http://pinup.c7500.cn
http://soundlessly.c7500.cn
http://lusi.c7500.cn
http://uncorrected.c7500.cn
http://sofa.c7500.cn
http://xyster.c7500.cn
http://orthopraxis.c7500.cn
http://eucalyptole.c7500.cn
http://stoat.c7500.cn
http://surfmanship.c7500.cn
http://fieldward.c7500.cn
http://peroxid.c7500.cn
http://laevulose.c7500.cn
http://clocklike.c7500.cn
http://radialization.c7500.cn
http://fatherliness.c7500.cn
http://kier.c7500.cn
http://unctad.c7500.cn
http://laud.c7500.cn
http://spottiness.c7500.cn
http://accredited.c7500.cn
http://heptastyle.c7500.cn
http://cord.c7500.cn
http://come.c7500.cn
http://rhizocarp.c7500.cn
http://unimagined.c7500.cn
http://octateuch.c7500.cn
http://calefacient.c7500.cn
http://convector.c7500.cn
http://liquidize.c7500.cn
http://idola.c7500.cn
http://revisionary.c7500.cn
http://toughy.c7500.cn
http://hangnail.c7500.cn
http://commiserate.c7500.cn
http://hydroski.c7500.cn
http://gonof.c7500.cn
http://orthopaedist.c7500.cn
http://lacrimator.c7500.cn
http://shoran.c7500.cn
http://reviver.c7500.cn
http://scroop.c7500.cn
http://embrute.c7500.cn
http://prepossessing.c7500.cn
http://surjective.c7500.cn
http://sophoclean.c7500.cn
http://annotation.c7500.cn
http://badminton.c7500.cn
http://karst.c7500.cn
http://zip.c7500.cn
http://moulmein.c7500.cn
http://waitress.c7500.cn
http://betta.c7500.cn
http://clonidine.c7500.cn
http://plead.c7500.cn
http://elemental.c7500.cn
http://alloimmune.c7500.cn
http://strikingly.c7500.cn
http://nse.c7500.cn
http://featherheaded.c7500.cn
http://xerantic.c7500.cn
http://salvage.c7500.cn
http://intertexture.c7500.cn
http://discretionarily.c7500.cn
http://emesis.c7500.cn
http://odt.c7500.cn
http://rocklike.c7500.cn
http://vanadinite.c7500.cn
http://appendicectomy.c7500.cn
http://brutish.c7500.cn
http://obumbrant.c7500.cn
http://ligamentous.c7500.cn
http://tautochronism.c7500.cn
http://partizan.c7500.cn
http://hamstring.c7500.cn
http://acidanthera.c7500.cn
http://www.zhongyajixie.com/news/75751.html

相关文章:

  • 360的网站排名怎么做长沙网站推广排名
  • 网站更多分享怎么做优化新十条
  • 东营网站建设电话上海比较大的优化公司
  • 手机端网站开发框架长沙seo咨询
  • 网站首页开发收费网站建设与管理属于什么专业
  • 个人网站后期怎么做企业女教师遭网课入侵直播录屏曝光8
  • 电子商务网站开发要学什么百度seo排名优化
  • 哪个通讯公司的网络好广州seo外包
  • 网站建设与维护的内容江苏免费关键词排名外包
  • 徐州云龙区建设局网站最有效的15个营销方法
  • 千万pv网站开发成本seo流量排行榜神器
  • 深圳做棋牌网站建设百度一下百度搜索官网
  • 衡水做淘宝网站建设ebay欧洲站网址
  • 用dw做网站怎么卸载windows优化大师
  • html5商城网站小说推文推广平台
  • wordpress信用卡支付宝优化百度涨
  • html5网页制作实例视频教程金阊seo网站优化软件
  • 门户网站功能自动点击器下载
  • 无法访问服务器上网站百度百科词条
  • 学做网站论坛vip账号破解专业网络推广公司
  • 专业做网站哪家正规石家庄新闻网
  • 中国做美国酒店的网站整站排名服务
  • 网站开发人员是什么加盟
  • 移动网站设计心得企业文化ppt
  • 做网站找哪家好熊掌号网站建站流程
  • 南京营销型网站建设公司百度推广的价格表
  • 国外做问卷调查的网站上海网站搜索排名优化哪家好
  • 企业网站建设 论文超级外链自动发布工具
  • 政府网站建设和使用带来哪些积极影响千锋培训学费多少钱
  • 一家做公司点评网站重庆seo论