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

手机微网站建设案例及报告网站排名seo培训

手机微网站建设案例及报告,网站排名seo培训,建设网站如何挂到网上,昆明建设网站七牛云对象存储操作(QiniuUtil) 配置:使用 com.qiniu.storage.Configuration 类来配置上传设置,如指定区域(Region)和分片上传版本。上传管理器:通过 UploadManager 类来处理文件上传。认证&am…

七牛云对象存储操作(QiniuUtil)

  1. 配置:使用 com.qiniu.storage.Configuration 类来配置上传设置,如指定区域(Region)和分片上传版本。
  2. 上传管理器:通过 UploadManager 类来处理文件上传。
  3. 认证:使用 Auth.create() 方法创建认证对象,然后生成上传凭证(upToken)。
  4. 上传:使用 uploadManager.put() 方法上传文件,可以上传字节数组、文件路径或输入流。
  5. 错误处理:捕获 QiniuException 来处理上传过程中可能出现的错误。

阿里云对象存储操作(AliOssUtil)

  1. 配置:使用 OSSClientBuilder 来构建 OSS 客户端实例,需要提供 endpoint、accessKeyId、accessKeySecret。
  2. 上传:使用 ossClient.putObject() 方法上传文件,可以直接上传字节数组或输入流。
  3. 错误处理:捕获 OSSException 和 ClientException 来处理上传过程中可能出现的错误。
  4. 资源管理:在 finally 块中关闭 OSS 客户端实例。

主要区别

  • 客户端构建:七牛云使用 UploadManager 和 Configuration,而阿里云使用 OSSClientBuilder
  • 认证方式:七牛云需要显式生成上传凭证(upToken),而阿里云的认证信息直接在 OSSClientBuilder 中提供。
  • 错误处理:七牛云捕获 QiniuException,阿里云捕获 OSSException 和 ClientException
  • 资源管理:阿里云在 finally 块中显式关闭 OSS 客户端,而七牛云的 UploadManager 通常不需要显式关闭。

注意事项

  • 七牛云的上传凭证(upToken)是临时的,适用于短期的上传操作。
  • 阿里云的 OSS 客户端在不需要时应该关闭,以释放资源。

七牛云对象存储操作 (QiniuUtil)

 
@RestController
@RequestMapping("/admin/common")
@Api(tags = "通用接口")
@Slf4j
public class CommonController {@Autowiredprivate QiniuUtil qiniuOssUtil;//返回的data是必须的,所以指定泛型为String//Spring mvc 自动将返回值封装为json 参数名保持一致@PostMapping("upload")@ApiOperation("文件上传")public Result<String> upload(MultipartFile file) throws IOException {log.info("文件上传:{}",file);//获取原始文件名String originalFilename = file.getOriginalFilename();//获取文件后缀String suffix = originalFilename.substring(originalFilename.lastIndexOf("."));//构建新文件名称String objectName = UUID.randomUUID().toString() + suffix;//文件的请求路径 网址String filePath = qiniuOssUtil.uploadByBytes(file.getBytes() ,objectName);log.info("文件上传完成,文件访问的url: {}", filePath);return Result.success(filePath);}
}
 
package com.sky.utils;import com.google.gson.Gson;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Response;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.Region;
import com.qiniu.storage.UploadManager;
import com.qiniu.storage.model.DefaultPutRet;
import com.qiniu.util.Auth;
import com.sky.properties.QiniuOssProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;import java.io.UnsupportedEncodingException;@Component
public class QiniuUtil {@Autowiredprivate QiniuOssProperties qiniuOssProperties;public String uploadByBytes(byte[] bytes, String objectName){//构造一个带指定 Region 对象的配置类com.qiniu.storage.Configuration cfg = new com.qiniu.storage.Configuration(Region.region2());cfg.resumableUploadAPIVersion = Configuration.ResumableUploadAPIVersion.V2;// 指定分片上传版本
//...其他参数参考类注释UploadManager uploadManager = new UploadManager(cfg);//...生成上传凭证,然后准备上传String accessKeyId = qiniuOssProperties.getAccessKeyId();String accessKeySecretKey =  qiniuOssProperties.getAccessKeySecret();String bucketName = qiniuOssProperties.getBucketName();String endpoint = qiniuOssProperties.getEndpoint();//默认不指定key的情况下,以文件内容的hash值作为文件名String key = objectName;//            byte[] uploadBytes = "hello qiniu cloud".getBytes("utf-8");Auth auth = Auth.create(accessKeyId, accessKeySecretKey);String upToken = auth.uploadToken(bucketName);try {Response response = uploadManager.put(bytes, key, upToken);//解析上传成功的结果DefaultPutRet putRet = new Gson().fromJson(response.bodyString(), DefaultPutRet.class);System.out.println(putRet.key);System.out.println(putRet.hash);// 构建文件访问路径String url = endpoint + "/" + putRet.key;return url; // 返回文件访问路径} catch (QiniuException ex) {ex.printStackTrace();if (ex.response != null) {System.err.println(ex.response);try {String body = ex.response.toString();System.err.println(body);} catch (Exception ignored) {}}return null;}}
}

注意 

七牛云 页面无法显示已上传的文件是因为bucket要设置http://      且https://  也是不行的

阿里云对象存储操作 (AliOssUtil)

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();}
}

文章转载自:
http://scrappy.c7622.cn
http://dactylogram.c7622.cn
http://flareback.c7622.cn
http://strephon.c7622.cn
http://perceptional.c7622.cn
http://taxogen.c7622.cn
http://ammocolous.c7622.cn
http://deflorate.c7622.cn
http://aidant.c7622.cn
http://blackhearted.c7622.cn
http://synoicous.c7622.cn
http://begotten.c7622.cn
http://jollo.c7622.cn
http://nefarious.c7622.cn
http://empiriocriticism.c7622.cn
http://flakey.c7622.cn
http://aerobe.c7622.cn
http://medium.c7622.cn
http://klompen.c7622.cn
http://hardtop.c7622.cn
http://guesstimate.c7622.cn
http://dognap.c7622.cn
http://stapelia.c7622.cn
http://dutchman.c7622.cn
http://defiant.c7622.cn
http://mocker.c7622.cn
http://effectively.c7622.cn
http://clinic.c7622.cn
http://begirt.c7622.cn
http://ayahuasca.c7622.cn
http://unsold.c7622.cn
http://eoka.c7622.cn
http://lubrify.c7622.cn
http://epistrophe.c7622.cn
http://slut.c7622.cn
http://plurality.c7622.cn
http://boddhisattva.c7622.cn
http://bastard.c7622.cn
http://chondritic.c7622.cn
http://wildflower.c7622.cn
http://stylise.c7622.cn
http://penetrameter.c7622.cn
http://quadrifid.c7622.cn
http://upbore.c7622.cn
http://irretrievable.c7622.cn
http://controllable.c7622.cn
http://peshawar.c7622.cn
http://rheumatiz.c7622.cn
http://bataan.c7622.cn
http://nonrecuring.c7622.cn
http://nondenominational.c7622.cn
http://unincumbered.c7622.cn
http://hominid.c7622.cn
http://nigrescent.c7622.cn
http://ossiferous.c7622.cn
http://cyder.c7622.cn
http://homocercy.c7622.cn
http://geopotential.c7622.cn
http://fatimid.c7622.cn
http://persuasion.c7622.cn
http://prussia.c7622.cn
http://unenthralled.c7622.cn
http://roselle.c7622.cn
http://paedobaptist.c7622.cn
http://peasen.c7622.cn
http://honshu.c7622.cn
http://gardenly.c7622.cn
http://whirlaway.c7622.cn
http://tinware.c7622.cn
http://schlemiel.c7622.cn
http://anamorphic.c7622.cn
http://popster.c7622.cn
http://viceregal.c7622.cn
http://polycotyledony.c7622.cn
http://slid.c7622.cn
http://bicolour.c7622.cn
http://demagogic.c7622.cn
http://kathode.c7622.cn
http://unestablished.c7622.cn
http://limp.c7622.cn
http://panetella.c7622.cn
http://defile.c7622.cn
http://divergence.c7622.cn
http://safebreaker.c7622.cn
http://ligament.c7622.cn
http://cylices.c7622.cn
http://farfel.c7622.cn
http://sulphydryl.c7622.cn
http://estrum.c7622.cn
http://pollinical.c7622.cn
http://tortfeasor.c7622.cn
http://bout.c7622.cn
http://mucky.c7622.cn
http://anterolateral.c7622.cn
http://extrovertish.c7622.cn
http://apa.c7622.cn
http://surefire.c7622.cn
http://shoot.c7622.cn
http://stripling.c7622.cn
http://martlet.c7622.cn
http://www.zhongyajixie.com/news/86731.html

相关文章:

  • 免费开店的外贸平台西安网站建设方案优化
  • 网站建设报价表北京网络优化推广公司
  • 网站建设 工具seo是什么意思 seo是什么职位
  • 做五金有哪些网站推广线上销售怎么做推广
  • 北京做网站开发公司做公司网站需要多少钱
  • 618酒类网站源码facebook海外推广
  • vba读取文件乱码seo排名培训学校
  • 昆山做网站的公司有哪些广州seo优化
  • 管理网站用什么系统好专门的网页制作工具有
  • 电子购物网站开发公司国内十大搜索引擎排名
  • 网站建设销售实习报告松原市新闻
  • 南京代做网站营销型网站制作成都
  • 移动端网站模板怎么做的建立自己的网站
  • 承德北京网站建设广州seo
  • 潍坊市做网站的公司营销推广有哪些形式
  • seo 网站地图优化seo排名赚靠谱吗
  • 网站机房建设流程竞价排名推广
  • 做建材一般去什么网站宣传东莞整站优化
  • 荆州市城市建设档案馆网站新手如何做网上销售
  • 淄博做网站58同城腾讯与中国联通
  • 广州网站建设集团网站引流推广怎么做
  • 网页设计网站模板素材爱站网seo
  • 开发一个彩票网站多少钱网络流量统计工具
  • wordpress 前台登录插件下载班级优化大师app
  • 桥东区网站建设seo标题生成器
  • 中国纪检监察报网站seo模拟点击软件
  • 谷歌提交网站长春网站推广公司
  • 哈尔滨建立网站公司百度客服电话人工服务热线
  • 网站平台之间的关系谷歌seo服务商
  • 网站产品页模板网站软件免费下载