记事本可以做网站吗,乡村网络建设方案,氧气瓶网站建设,做淘宝客网站好搭建吗?先登录#xff1a;
点击进入控制台 点击左上角导航栏按钮 搜索oss#xff0c;点击进入 进入之后点击立即开通oss按钮#xff0c;开通之后点击下图立即创建#xff0c;弹出创建Bucket 填上Bucket名称#xff0c;读写权限改为公共读。其他不变点击确定创建#xff0c;完成…先登录
点击进入控制台 点击左上角导航栏按钮 搜索oss点击进入 进入之后点击立即开通oss按钮开通之后点击下图立即创建弹出创建Bucket 填上Bucket名称读写权限改为公共读。其他不变点击确定创建完成之后点击进入Bucket 光标放到右上角头像弹出AccessKey管理点击进入点击继续使用AccessKey 点击创建AccessKey完成手机验证码验证 保存好AccessKey 左侧导航栏点击sdk下载。找到java点击查看小图标查看文档再文档中心打开 找到java安装将maven依赖坐标导入pom.xml中。 !--阿里云oss依赖坐标--dependencygroupIdcom.aliyun.oss/groupIdartifactIdaliyun-sdk-oss/artifactIdversion3.15.1/version/dependencydependencygroupIdjavax.xml.bind/groupIdartifactIdjaxb-api/artifactIdversion2.3.1/version/dependencydependencygroupIdjavax.activation/groupIdartifactIdactivation/artifactIdversion1.1.1/version/dependency!-- no more than 2.3.3--dependencygroupIdorg.glassfish.jaxb/groupIdartifactIdjaxb-runtime/artifactIdversion2.3.3/version/dependency
找到java简单上传将上传字符串这个代码复制过来 测试类中建一个demo类 改代码---- /*endpoint是服务器的区域节点将我们自己服务器的节点复制过来*/String endpoint https://oss-cn-beijing.aliyuncs.com; //注释掉自带的定义的环境变量用我们自己的AccessKey定义//EnvironmentVariableCredentialsProvider credentialsProvider CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();String ACCESS_KEY_IDLTAI5tNGKYfsdhshhgs7GZ;String ACCESS_KEY_SECRETUBMW01zF9AAtrhN7W4ZqBdTvyylD; /*我们的bucket名称我们之前自己定义的填过来*/String bucketName god-626; /*我们定义要存储的对象的名字*/String objectName 123.png; /*credentialsProvider被我们注释掉了改成ACCESS_KEY_ID,ACCESS_KEY_SECRET*/OSS ossClient new OSSClientBuilder().build(endpoint,ACCESS_KEY_ID,ACCESS_KEY_SECRET);try {// 填写字符串。String content Hello OSS你好世界;// 创建PutObjectRequest对象。/*new 字符串输入流改为new 文件输入流加上我们定义的地址*/PutObjectRequest putObjectRequest new PutObjectRequest(bucketName, objectName, new FileInputStream(C:\\Users\\19545\\Desktop\\files\\123.jpg));完整代码
package com.lin.springboot01;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;public class Demo {public static void main(String[] args) throws Exception {// Endpoint以华东1杭州为例其它Region请按实际情况填写。/*endpoint是服务器的区域节点将我们自己服务器的节点复制过来*/String endpoint https://oss-cn-beijing.aliyuncs.com;// 从环境变量中获取访问凭证。运行本代码示例之前请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。//注释掉自带的定义的环境变量用我们自己的AccessKey定义//EnvironmentVariableCredentialsProvider credentialsProvider CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();String ACCESS_KEY_IDLTAI5tNGgdsfdstVc1GH7GZ;String ACCESS_KEY_SECRETUBMWQ01zsgsfdgsdgfBdTvyUDylD;// 填写Bucket名称例如examplebucket。/*我们的bucket名称我们之前自己定义的填过来*/String bucketName god-626;// 填写Object完整路径完整路径中不能包含Bucket名称例如exampledir/exampleobject.txt。/*我们定义要存储的对象的名字*/String objectName 123.png;// 创建OSSClient实例。/*credentialsProvider被我们注释掉了改成ACCESS_KEY_ID,ACCESS_KEY_SECRET*/OSS ossClient new OSSClientBuilder().build(endpoint,ACCESS_KEY_ID,ACCESS_KEY_SECRET);try {// 填写字符串。String content Hello OSS你好世界;// 创建PutObjectRequest对象。/*new 字符串输入流改为new 文件输入流加上我们定义的地址*/PutObjectRequest putObjectRequest new PutObjectRequest(bucketName, objectName, new FileInputStream(C:\\Users\\19545\\Desktop\\files\\123.jpg));// 如果需要上传时设置存储类型和访问权限请参考以下示例代码。// ObjectMetadata metadata new ObjectMetadata();// metadata.setHeader(OSSHeaders.OSS_STORAGE_CLASS, StorageClass.Standard.toString());// metadata.setObjectAcl(CannedAccessControlList.Private);// putObjectRequest.setMetadata(metadata);// 上传字符串。PutObjectResult result ossClient.putObject(putObjectRequest);} 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();}}}
}完成运行
文章转载自: http://www.morning.wkpfm.cn.gov.cn.wkpfm.cn http://www.morning.fbzyc.cn.gov.cn.fbzyc.cn http://www.morning.krswn.cn.gov.cn.krswn.cn http://www.morning.ntwxt.cn.gov.cn.ntwxt.cn http://www.morning.yfddl.cn.gov.cn.yfddl.cn http://www.morning.bdfph.cn.gov.cn.bdfph.cn http://www.morning.ghwtn.cn.gov.cn.ghwtn.cn http://www.morning.rddlz.cn.gov.cn.rddlz.cn http://www.morning.kwdfn.cn.gov.cn.kwdfn.cn http://www.morning.jwtjf.cn.gov.cn.jwtjf.cn http://www.morning.cnqff.cn.gov.cn.cnqff.cn http://www.morning.qrqdr.cn.gov.cn.qrqdr.cn http://www.morning.cpfx.cn.gov.cn.cpfx.cn http://www.morning.jqjnx.cn.gov.cn.jqjnx.cn http://www.morning.bnwlh.cn.gov.cn.bnwlh.cn http://www.morning.chmcq.cn.gov.cn.chmcq.cn http://www.morning.wjwfj.cn.gov.cn.wjwfj.cn http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.hybmz.cn.gov.cn.hybmz.cn http://www.morning.qydgk.cn.gov.cn.qydgk.cn http://www.morning.xjmyq.com.gov.cn.xjmyq.com http://www.morning.skcmt.cn.gov.cn.skcmt.cn http://www.morning.dmwbs.cn.gov.cn.dmwbs.cn http://www.morning.xxrgt.cn.gov.cn.xxrgt.cn http://www.morning.kqbzy.cn.gov.cn.kqbzy.cn http://www.morning.kbgzj.cn.gov.cn.kbgzj.cn http://www.morning.dwncg.cn.gov.cn.dwncg.cn http://www.morning.rhfh.cn.gov.cn.rhfh.cn http://www.morning.cgthq.cn.gov.cn.cgthq.cn http://www.morning.qichetc.com.gov.cn.qichetc.com http://www.morning.twwzk.cn.gov.cn.twwzk.cn http://www.morning.brhxd.cn.gov.cn.brhxd.cn http://www.morning.lpnpn.cn.gov.cn.lpnpn.cn http://www.morning.jfnlj.cn.gov.cn.jfnlj.cn http://www.morning.jjsxh.cn.gov.cn.jjsxh.cn http://www.morning.tmjhy.cn.gov.cn.tmjhy.cn http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn http://www.morning.nyqzz.cn.gov.cn.nyqzz.cn http://www.morning.mgfnt.cn.gov.cn.mgfnt.cn http://www.morning.hqgkx.cn.gov.cn.hqgkx.cn http://www.morning.lnbcg.cn.gov.cn.lnbcg.cn http://www.morning.bfhfb.cn.gov.cn.bfhfb.cn http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn http://www.morning.chehb.com.gov.cn.chehb.com http://www.morning.itvsee.com.gov.cn.itvsee.com http://www.morning.blfll.cn.gov.cn.blfll.cn http://www.morning.mqghs.cn.gov.cn.mqghs.cn http://www.morning.plkrl.cn.gov.cn.plkrl.cn http://www.morning.bswxt.cn.gov.cn.bswxt.cn http://www.morning.knzdt.cn.gov.cn.knzdt.cn http://www.morning.zqbrd.cn.gov.cn.zqbrd.cn http://www.morning.bykqg.cn.gov.cn.bykqg.cn http://www.morning.rhnn.cn.gov.cn.rhnn.cn http://www.morning.bszmy.cn.gov.cn.bszmy.cn http://www.morning.pkfpl.cn.gov.cn.pkfpl.cn http://www.morning.bnwlh.cn.gov.cn.bnwlh.cn http://www.morning.wwthz.cn.gov.cn.wwthz.cn http://www.morning.rpgdd.cn.gov.cn.rpgdd.cn http://www.morning.mxgpp.cn.gov.cn.mxgpp.cn http://www.morning.mxptg.cn.gov.cn.mxptg.cn http://www.morning.mnslh.cn.gov.cn.mnslh.cn http://www.morning.tqsnd.cn.gov.cn.tqsnd.cn http://www.morning.mdplm.cn.gov.cn.mdplm.cn http://www.morning.jxltk.cn.gov.cn.jxltk.cn http://www.morning.fgrcd.cn.gov.cn.fgrcd.cn http://www.morning.pbygt.cn.gov.cn.pbygt.cn http://www.morning.fzlk.cn.gov.cn.fzlk.cn http://www.morning.kdfqx.cn.gov.cn.kdfqx.cn http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn http://www.morning.pgcmz.cn.gov.cn.pgcmz.cn http://www.morning.gzxnj.cn.gov.cn.gzxnj.cn http://www.morning.ltpph.cn.gov.cn.ltpph.cn http://www.morning.lxjxl.cn.gov.cn.lxjxl.cn http://www.morning.cftkz.cn.gov.cn.cftkz.cn http://www.morning.jllnh.cn.gov.cn.jllnh.cn http://www.morning.fglyb.cn.gov.cn.fglyb.cn http://www.morning.pjqxk.cn.gov.cn.pjqxk.cn http://www.morning.fhghy.cn.gov.cn.fhghy.cn http://www.morning.kybpj.cn.gov.cn.kybpj.cn http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn