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

江苏省交通建设监理协会网站seo排名点击器曝光行者seo

江苏省交通建设监理协会网站,seo排名点击器曝光行者seo,自学网站建设哪些网站,陕西免费做网站目录 拉取docker镜像 minio所需要的依赖 文件存放的位置 手动上传文件到minio中 工具类上传 yml配置 config类 service类 启动类 测试类 图片 视频 删除minio服务器的文件 下载minio服务器的文件 拉取docker镜像 拉取稳定版本:docker pull minio/minio:RELEASE.20…

目录

拉取docker镜像

minio所需要的依赖

文件存放的位置

手动上传文件到minio中

 工具类上传

yml配置

config类

service类

启动类

 测试类

图片

视频

删除minio服务器的文件

下载minio服务器的文件


拉取docker镜像

拉取稳定版本:docker pull minio/minio:RELEASE.2021-06-17T00-10-46Z-28-gac7697426创建并运行容器:   docker run -d -p 9000:9000 --name minio \-e "MINIO_ACCESS_KEY=minio" \-e "MINIO_SECRET_KEY=minio123" \-v /path/to/data:/data \-v /path/to/config:/root/.minio \minio/minio:RELEASE.2021-06-17T00-10-46Z server /data访问minmo系统: http://192.168.74.128:9000

minio所需要的依赖

        <dependency><groupId>io.minio</groupId><artifactId>minio</artifactId><version>7.1.0</version></dependency>

文件存放的位置

退出minio容器

exit

手动上传文件到minio中

    public static void main(String[] args) {FileInputStream fileInputStream = null;try {fileInputStream =  new FileInputStream("e:\\index.js");;//1.创建minio链接客户端MinioClient minioClient = MinioClient.builder().credentials("minio", "minio123").endpoint("http://192.168.74.128:9000").build();//2.上传PutObjectArgs putObjectArgs = PutObjectArgs.builder().object("plugins/js/index.js")//文件名.contentType("text/js")//文件类型.bucket("leadnews")//桶名词  与minio创建的名词一致.stream(fileInputStream, fileInputStream.available(), -1) //文件流.build();minioClient.putObject(putObjectArgs);} catch (Exception ex) {ex.printStackTrace();}}

 工具类上传

yml配置

minio:accessKey: miniosecretKey: minio123bucket: leadnewsendpoint: http://192.168.74.128:9000readPath: http://192.168.74.128:9000

config类

package com.heima.file.config;import com.heima.file.service.FileStorageService;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Data
@Configuration
@EnableConfigurationProperties({MinIOConfigProperties.class})
//当引入FileStorageService接口时
@ConditionalOnClass(FileStorageService.class)
public class MinIOConfig {@Autowiredprivate MinIOConfigProperties minIOConfigProperties;@Beanpublic MinioClient buildMinioClient() {return MinioClient.builder().credentials(minIOConfigProperties.getAccessKey(), minIOConfigProperties.getSecretKey()).endpoint(minIOConfigProperties.getEndpoint()).build();}
}
package com.ma.config;import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;import java.io.Serializable;@Data
@ConfigurationProperties(prefix = "minio")  // 文件上传 配置前缀file.oss
public class MinIOConfigProperties implements Serializable {private String accessKey;private String secretKey;private String bucket;private String endpoint;private String readPath;
}

service类

package com.ma.service;import java.io.InputStream;/*** @author itheima*/
public interface FileStorageService {/***  上传图片文件* @param prefix  文件前缀* @param filename  文件名* @param inputStream 文件流* @return  文件全路径*/public String uploadImgFile(String prefix, String filename,InputStream inputStream);/***  上传html文件* @param prefix  文件前缀* @param filename   文件名* @param inputStream  文件流* @return  文件全路径*/public String uploadHtmlFile(String prefix, String filename,InputStream inputStream);/*** 删除文件* @param pathUrl  文件全路径*/public void delete(String pathUrl);/*** 下载文件* @param pathUrl  文件全路径* @return**/public byte[]  downLoadFile(String pathUrl);}
package com.ma.service.impl;import com.ma.config.MinIOConfig;
import com.ma.config.MinIOConfigProperties;
import com.ma.service.FileStorageService;
import io.minio.GetObjectArgs;
import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.RemoveObjectArgs;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;@Slf4j
@EnableConfigurationProperties(MinIOConfigProperties.class)
@Import(MinIOConfig.class)
@Service
public class MinIOFileStorageService implements FileStorageService {@Autowiredprivate MinioClient minioClient;@Autowiredprivate MinIOConfigProperties minIOConfigProperties;private final static String separator = "/";/*** @param dirPath* @param filename  yyyy/mm/dd/file.jpg* @return*/public String builderFilePath(String dirPath,String filename) {StringBuilder stringBuilder = new StringBuilder(50);if(!StringUtils.isEmpty(dirPath)){stringBuilder.append(dirPath).append(separator);}SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");String todayStr = sdf.format(new Date());stringBuilder.append(todayStr).append(separator);stringBuilder.append(filename);return stringBuilder.toString();}/***  上传图片文件* @param prefix  文件前缀* @param filename  文件名* @param inputStream 文件流* @return  文件全路径*/@Overridepublic String uploadImgFile(String prefix, String filename,InputStream inputStream) {String filePath = builderFilePath(prefix, filename);try {PutObjectArgs putObjectArgs = PutObjectArgs.builder().object(filePath).contentType("image/jpg").bucket(minIOConfigProperties.getBucket()).stream(inputStream,inputStream.available(),-1).build();minioClient.putObject(putObjectArgs);StringBuilder urlPath = new StringBuilder(minIOConfigProperties.getReadPath());urlPath.append(separator+minIOConfigProperties.getBucket());urlPath.append(separator);urlPath.append(filePath);return urlPath.toString();}catch (Exception ex){log.error("minio put file error.",ex);throw new RuntimeException("上传文件失败");}}/***  上传html文件* @param prefix  文件前缀* @param filename   文件名* @param inputStream  文件流* @return  文件全路径*/@Overridepublic String uploadHtmlFile(String prefix, String filename,InputStream inputStream) {String filePath = builderFilePath(prefix, filename);try {PutObjectArgs putObjectArgs = PutObjectArgs.builder().object(filePath).contentType("text/html").bucket(minIOConfigProperties.getBucket()).stream(inputStream,inputStream.available(),-1).build();minioClient.putObject(putObjectArgs);StringBuilder urlPath = new StringBuilder(minIOConfigProperties.getReadPath());urlPath.append(separator+minIOConfigProperties.getBucket());urlPath.append(separator);urlPath.append(filePath);return urlPath.toString();}catch (Exception ex){log.error("minio put file error.",ex);ex.printStackTrace();throw new RuntimeException("上传文件失败");}}/*** 删除文件* @param pathUrl  文件全路径*/@Overridepublic void delete(String pathUrl) {String key = pathUrl.replace(minIOConfigProperties.getEndpoint()+"/","");int index = key.indexOf(separator);String bucket = key.substring(0,index);String filePath = key.substring(index+1);// 删除ObjectsRemoveObjectArgs removeObjectArgs = RemoveObjectArgs.builder().bucket(bucket).object(filePath).build();try {minioClient.removeObject(removeObjectArgs);} catch (Exception e) {log.error("minio remove file error.  pathUrl:{}",pathUrl);e.printStackTrace();}}/*** 下载文件* @param pathUrl  文件全路径* @return  文件流**/@Overridepublic byte[] downLoadFile(String pathUrl)  {String key = pathUrl.replace(minIOConfigProperties.getEndpoint()+"/","");int index = key.indexOf(separator);String bucket = key.substring(0,index);String filePath = key.substring(index+1);InputStream inputStream = null;try {inputStream = minioClient.getObject(GetObjectArgs.builder().bucket(minIOConfigProperties.getBucket()).object(filePath).build());} catch (Exception e) {log.error("minio down file error.  pathUrl:{}",pathUrl);e.printStackTrace();}ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();byte[] buff = new byte[100];int rc = 0;while (true) {try {if (!((rc = inputStream.read(buff, 0, 100)) > 0)) break;} catch (IOException e) {e.printStackTrace();}byteArrayOutputStream.write(buff, 0, rc);}return byteArrayOutputStream.toByteArray();}
}

启动类

@SpringBootApplication@ComponentScan(basePackages = {"com.ma.config", "com.ma.service"})
public class SpringBootTest01Application {public static void main(String[] args) {SpringApplication.run(SpringBootTest01Application.class, args);}
}

 测试类

图片

package com.ma.springboottest01;import com.ma.service.FileStorageService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.io.FileInputStream;
import java.io.InputStream;@SpringBootTest
class SpringBootTest01ApplicationTests {@Autowiredprivate FileStorageService fileStorageService;@Testvoid contextLoads() {// 示例用法try {// 创建一个InputStream,例如从本地文件获取InputStream fileInputStream = new FileInputStream("D:\\Image\\星空.jpg");// 调用uploadImgFile方法进行文件上传String prefix = "user_images/"; // 设置文件前缀String filename = "unique_image_name.jpg"; // 设置文件名
//            String url = uploadImgFile(prefix, filename, fileInputStream);// url现在包含了上传文件的访问路径String url = fileStorageService.uploadImgFile(prefix, filename, fileInputStream);System.out.println("File uploaded successfully. URL: " + url);} catch (Exception e) {// 处理上传失败的情况e.printStackTrace();}}
}

视频

package com.ma.springboottest01;import com.ma.service.FileStorageService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;import java.io.FileInputStream;
import java.io.InputStream;@SpringBootTest
class SpringBootTest01ApplicationTests {@Autowiredprivate FileStorageService fileStorageService;@Testvoid contextLoads() {// 示例用法try {// 创建一个InputStream,例如从本地文件获取
//            InputStream fileInputStream = new FileInputStream("D:\\Image\\星空.jpg");InputStream fileInputStream = new FileInputStream("D:\\video\\test.mp4");// 调用uploadImgFile方法进行文件上传// 设置文件前缀和文件名String prefix = "videos/";String filename = "example_video.mp4";
//            String url = uploadImgFile(prefix, filename, fileInputStream);// url现在包含了上传文件的访问路径String url = fileStorageService.uploadImgFile(prefix, filename, fileInputStream);System.out.println("File uploaded successfully. URL: " + url);} catch (Exception e) {// 处理上传失败的情况e.printStackTrace();}}
}

删除minio服务器的文件

    @Testvoid t2(){fileStorageService.delete("http://192.168.74.128:9000/leadnews/videos//2023/11/27/example_video.mp4");}

下载minio服务器的文件

    @Testvoid t2() {byte[] bytes = fileStorageService.downLoadFile("http://192.168.74.128:9000/leadnews/user_images//2023/11/27/unique_image_name.jpg");// 保存到本地文件的示例String localFilePath = "E:guo.jpg//"; // 替换为实际的本地文件路径saveToFile(bytes, localFilePath);}public static void saveToFile(byte[] fileContent, String localFilePath) {try (FileOutputStream fos = new FileOutputStream(localFilePath)) {fos.write(fileContent);System.out.println("File saved locally: " + localFilePath);} catch (IOException e) {e.printStackTrace();}}


文章转载自:
http://carcase.rnds.cn
http://namierite.rnds.cn
http://uneducational.rnds.cn
http://illuminometer.rnds.cn
http://succuba.rnds.cn
http://derv.rnds.cn
http://phlebolite.rnds.cn
http://tetracarpellary.rnds.cn
http://tribolet.rnds.cn
http://appulsively.rnds.cn
http://psychotechnics.rnds.cn
http://ferny.rnds.cn
http://cymiferous.rnds.cn
http://symmetrize.rnds.cn
http://ern.rnds.cn
http://calcareously.rnds.cn
http://trublemaker.rnds.cn
http://empiristic.rnds.cn
http://immoralism.rnds.cn
http://interpellator.rnds.cn
http://woken.rnds.cn
http://riffian.rnds.cn
http://necrogenic.rnds.cn
http://wavelike.rnds.cn
http://arrowwood.rnds.cn
http://overcooked.rnds.cn
http://jiangxi.rnds.cn
http://miserably.rnds.cn
http://originally.rnds.cn
http://pneumatometer.rnds.cn
http://sozin.rnds.cn
http://constructional.rnds.cn
http://sewer.rnds.cn
http://hayrake.rnds.cn
http://homograph.rnds.cn
http://pseudologue.rnds.cn
http://aerographer.rnds.cn
http://eccaleobion.rnds.cn
http://phototonus.rnds.cn
http://solarometer.rnds.cn
http://bondsman.rnds.cn
http://rosebay.rnds.cn
http://archontic.rnds.cn
http://chanteur.rnds.cn
http://muskellunge.rnds.cn
http://marrier.rnds.cn
http://travail.rnds.cn
http://regimentation.rnds.cn
http://prolong.rnds.cn
http://vagary.rnds.cn
http://disendowment.rnds.cn
http://gilbertese.rnds.cn
http://cornettist.rnds.cn
http://supple.rnds.cn
http://testibiopalladite.rnds.cn
http://appaloosa.rnds.cn
http://fuchsine.rnds.cn
http://revealed.rnds.cn
http://subvene.rnds.cn
http://bydgoszcz.rnds.cn
http://irruption.rnds.cn
http://uniflagellate.rnds.cn
http://consensus.rnds.cn
http://horoscopic.rnds.cn
http://restes.rnds.cn
http://bureaucratist.rnds.cn
http://opodeldoc.rnds.cn
http://fatheaded.rnds.cn
http://radiolucent.rnds.cn
http://crestfallen.rnds.cn
http://hac.rnds.cn
http://tambov.rnds.cn
http://lotusland.rnds.cn
http://trioicous.rnds.cn
http://subprogram.rnds.cn
http://lineate.rnds.cn
http://intolerant.rnds.cn
http://liability.rnds.cn
http://lobstering.rnds.cn
http://cgt.rnds.cn
http://thermogenesis.rnds.cn
http://didymous.rnds.cn
http://orthoptera.rnds.cn
http://iconolatry.rnds.cn
http://selsyn.rnds.cn
http://aftertreatment.rnds.cn
http://nard.rnds.cn
http://claudia.rnds.cn
http://roundsman.rnds.cn
http://fco.rnds.cn
http://mainboard.rnds.cn
http://millionth.rnds.cn
http://hame.rnds.cn
http://orthopedics.rnds.cn
http://foeman.rnds.cn
http://canvas.rnds.cn
http://enantiomorphism.rnds.cn
http://summoner.rnds.cn
http://trudge.rnds.cn
http://cystoma.rnds.cn
http://www.hrbkazy.com/news/58186.html

相关文章:

  • 学做网站培训机构网站收录网
  • 四川省建设工程交易中心网站杭州网站外包
  • wordpress后台样式免费网站优化排名
  • 永久网站建设必应搜索引擎
  • 深圳龙华政府在线官网百度seoo优化软件
  • 娱乐视频直播网站建设举例网络营销的例子
  • 拍卖网站咋做临沂做网站建设公司
  • asp做网站技术怎样成人短期技能培训
  • 展示商品的网站怎么做百度收录在线提交
  • 沈阳网站建设技术公司排名seo是什么意思
  • 网站内容管理系统下载大数据营销系统软件
  • 浏览器网页打不开是什么原因深圳专业seo
  • 简洁手机导航网站模板下载安装十大营销策略有哪些
  • 网站升级公告模板百度关键词优化怎么做
  • java用ssm做电商网站seo营销是什么
  • 网站备案注销找哪个部门在百度做广告多少钱
  • wordpress文章添加meta一键优化清理
  • 用javascirpt做的网站百度竞价推广教程
  • wordpress排版教程视频谈谈你对seo概念的理解
  • 做网站用图片推广app接单网
  • 长沙网站seo推广公司友情链接交换形式有哪些
  • 做网站业务员应该了解什么seo按照搜索引擎的
  • 萧山城市建设网站网店推广有哪些
  • 服装设计与工程东莞seo网络公司
  • 建设旅游网站的好处优化设计答案
  • 网站建设丨金手指谷哥12河北网站seo外包
  • 个人网站做百度推广百度网站提交入口网址
  • 阳泉集团网站建设微信推广平台自己可以做
  • 主做销售招聘的招聘网站有哪些seo排名专业公司
  • 用dw制作公司网站百度关键词排名查询工具