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

360免费建站怎么做软文推广营销服务平台

360免费建站怎么做,软文推广营销服务平台,e展网网站的建设情况,wordpress默认页面设置方法官方文档 https://help.aliyun.com/zh/oss/developer-reference/java 准备工作 windows安装好JDK,这里使用JDK1.8为例 windows安装好IDEA,这里使用IDEA2022 登录阿里云控制台,通过免费试用OSS或开通OSS 步骤 配置访问凭证 有临时和长期…

官方文档

https://help.aliyun.com/zh/oss/developer-reference/java

准备工作

  • windows安装好JDK,这里使用JDK1.8为例

  • windows安装好IDEA,这里使用IDEA2022

  • 登录阿里云控制台,通过免费试用OSS或开通OSS

步骤

配置访问凭证

有临时和长期访问凭证,简单起见,这里使用长期访问凭证。

配置RAM用户的访问密钥

1.创建RAM用户

登录阿里云,搜索访问控制,进入RAM 访问控制
在这里插入图片描述

在RAM 访问控制中,创建RAM用户
在这里插入图片描述
填写用户信息,勾选相关访问方式,点击确定
在这里插入图片描述
安全验证,根据提示进行其中一个验证。
在这里插入图片描述
得到RAM用户的相关信息,例如登录名称、登录密码、AccessKey ID和Access Secret
在这里插入图片描述

点击用户,找到刚创建的RAM用户一行,点击添加权限

在这里插入图片描述
添加AliyunOSSFullAccess权限
在这里插入图片描述

2.配置RAM用户的访问密钥。

有两种方式配置RAM用户的访问密钥

  • 设置环境变量
  • 代码嵌入
    把AccessKey ID和Access Secret设置在环境变量里比直接代码嵌入的方式更加安全些,两种方式选择其中之一即可。
设置环境变量

打开cmd命令行。

执行以下命令配置RAM用户的访问密钥。

set OSS_ACCESS_KEY_ID=LTAI4GDty8ab9W4Y1D****
set OSS_ACCESS_KEY_SECRET=IrVTNZNy5yQelTETg0cZML3TQn**** 

注意: OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET修改为对应AccessKey ID和Access Secret的值。
在这里插入图片描述

执行以下命令以使更改生效。

setx OSS_ACCESS_KEY_ID "%OSS_ACCESS_KEY_ID%"
setx OSS_ACCESS_KEY_SECRET "%OSS_ACCESS_KEY_SECRET%"

这个过程其实是往用户的环境变量里设置相应的值(用图形界面设置也一样)
在这里插入图片描述

执行以下命令验证环境变量配置。

echo %OSS_ACCESS_KEY_ID%
echo %OSS_ACCESS_KEY_SECRET%

成功返回示例如下:

LTAI4GDty8ab9W4Y1D****
IrVTNZNy5yQelTETg0cZML3TQn**** 

从环境变量中获取RAM用户的访问密钥。

// 使用环境变量中获取的RAM用户的访问密钥配置访问凭证。
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();

注意:设置环境变量后,如果之前已经打开IDEA,后面使用代码去获取环境变量时,需要重启IDEA,才能获取到新的环境变量设置。否则获取到的环境变量为null

代码嵌入
// RAM用户的访问密钥(AccessKey ID和AccessKey Secret)。
String accessKeyId = "yourAccessKeyId";
String accessKeySecret = "yourAccessKeySecret";
// 使用代码嵌入的RAM用户的访问密钥配置访问凭证。
CredentialsProvider credentialsProvider = new DefaultCredentialProvider(accessKeyId, accessKeySecret);

代码开发

1. 创建maven工程

打开IDEA->点击File->New Project
在这里插入图片描述

2. 添加sdk依赖
    <dependencies><dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.15.1</version></dependency></dependencies>

刷新依赖

3. 功能代码开发

使用SDK API实现创建Bucket、列举Bucket文件、上传文件、下载文件、删除文件。代码参考官方帮助文档。
代码结构如下:
在这里插入图片描述

创建Bucket
package org.example;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;public class CreateBucketDemo {public static void main(String[] args) throws Exception {// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();// 填写Bucket名称,例如examplebucket。String bucketName = "examplebucket-test-test900";// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);try {// 创建存储空间。ossClient.createBucket(bucketName);} 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();}}}
}

*注意:修改endpointbucketName bucketName 不能有重复。

运行后,在阿里云控制台查看到bucket创建成功如下
在这里插入图片描述
可以手动上传一些文件到bucket里,点击Bucket名称
在这里插入图片描述
进入bucket文件列表页面,通过上传文件创建目录等方式让Bucket里得到一些目录和文件。
在这里插入图片描述

列举Bucket文件
package org.example;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProvider;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.ObjectListing;public class ListFileDemo {public static void main(String[] args) throws Exception {// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";// 嵌入代码// RAM用户的访问密钥(AccessKey ID和AccessKey Secret)。注意修改xxx的值String accessKeyId = "xxx";String accessKeySecret = "xxx";// 使用代码嵌入的RAM用户的访问密钥配置访问凭证。CredentialsProvider credentialsProvider = new DefaultCredentialProvider(accessKeyId, accessKeySecret);// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。
//        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();// 填写Bucket名称,例如examplebucket。String bucketName = "examplebucket-test-test900";// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);try {// ossClient.listObjects返回ObjectListing实例,包含此次listObject请求的返回结果。ObjectListing objectListing = ossClient.listObjects(bucketName);// objectListing.getObjectSummaries获取所有文件的描述信息。for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {System.out.println(" - " + objectSummary.getKey() + "  " +"(size = " + objectSummary.getSize() + ")");}} 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();}}}
}

使用代码嵌入的方式得到RAM用户的访问密钥。
注意修改accessKeyIdaccessKeySecret的值。
运行代码能看到一些文件
在这里插入图片描述

上传文件
package org.example;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import java.io.ByteArrayInputStream;public class UploadFileDemo {public static void main(String[] args) throws Exception {// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();// 填写Bucket名称,例如examplebucket。String bucketName = "examplebucket-test-test900";// 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。String objectName = "file/uploadobject1.txt";// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);try {String content = "Hello OSS";ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(content.getBytes()));} 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();}}}
}

运行后,查看阿里云控制台,多了一个uploadobject1.txt文件,
在这里插入图片描述
可以验证uploadobject1.txt的内容为

Hello OSS
下载文件
package org.example;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.model.OSSObject;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;public class DownloadFileDemo {public static void main(String[] args) throws Exception {// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();// 填写Bucket名称,例如examplebucket。String bucketName = "examplebucket-test-test900";// 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。String objectName = "file/emp.sql";// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);try {// 调用ossClient.getObject返回一个OSSObject实例,该实例包含文件内容及文件元信息。OSSObject ossObject = ossClient.getObject(bucketName, objectName);// 调用ossObject.getObjectContent获取文件输入流,可读取此输入流获取其内容。InputStream content = ossObject.getObjectContent();if (content != null) {BufferedReader reader = new BufferedReader(new InputStreamReader(content));while (true) {String line = reader.readLine();if (line == null) {break;}System.out.println("\n" + line);//这里简单打印每行内容}// 数据读取完成后,获取的流必须关闭,否则会造成连接泄漏,导致请求无连接可用,程序无法正常工作。content.close();}} 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();}}}
}

运行程序,看到emp.sql的内容
在这里插入图片描述

删除文件
package org.example;import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;public class DeleteFileDemo {public static void main(String[] args) throws Exception {// Endpoint以华东1(杭州)为例,其它Region请按实际情况填写。String endpoint = "https://oss-cn-shenzhen.aliyuncs.com";// 从环境变量中获取访问凭证。运行本代码示例之前,请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();// 填写Bucket名称,例如examplebucket。String bucketName = "examplebucket-test-test900";// 填写Object完整路径,例如exampledir/exampleobject.txt。Object完整路径中不能包含Bucket名称。String objectName = "file/uploadobject1.txt";// 创建OSSClient实例。OSS ossClient = new OSSClientBuilder().build(endpoint, credentialsProvider);try {// 删除文件。ossClient.deleteObject(bucketName, objectName);} 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();}}}
}

运行程序后,刷新Bucket列表,看到file/uploadobject1.txt被删除了。
在这里插入图片描述
代码总结:
在使用OSS SDK时,需要先创建OSSClient实例ossClient,然后调用对应API方法。例如:

  • 创建Bucket: ossClient.createBucket(bucketName)
  • 列举Bucket文件: ossClient.listObjects(bucketName)
  • 上传文件:ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(content.getBytes()))
  • 下载文件:ossClient.getObject(bucketName, objectName).getObjectContent()
  • 删除文件:ossClient.deleteObject(bucketName, objectName)

完成!enjoy it!


文章转载自:
http://tokay.tyjp.cn
http://kymograph.tyjp.cn
http://dryopithecine.tyjp.cn
http://incredulity.tyjp.cn
http://magi.tyjp.cn
http://incongruously.tyjp.cn
http://septisyllable.tyjp.cn
http://biosonar.tyjp.cn
http://explain.tyjp.cn
http://armill.tyjp.cn
http://pecos.tyjp.cn
http://nachus.tyjp.cn
http://gastronom.tyjp.cn
http://quadriphonics.tyjp.cn
http://peytral.tyjp.cn
http://hamiticize.tyjp.cn
http://englobement.tyjp.cn
http://unanimous.tyjp.cn
http://basketball.tyjp.cn
http://enterectomy.tyjp.cn
http://interrogatory.tyjp.cn
http://khet.tyjp.cn
http://duumviri.tyjp.cn
http://riouw.tyjp.cn
http://topnotch.tyjp.cn
http://glaucomatous.tyjp.cn
http://bibliomancy.tyjp.cn
http://zymosis.tyjp.cn
http://lithuria.tyjp.cn
http://litmusless.tyjp.cn
http://rhinology.tyjp.cn
http://ochlocracy.tyjp.cn
http://euphrasy.tyjp.cn
http://vainglorious.tyjp.cn
http://resaid.tyjp.cn
http://ctn.tyjp.cn
http://squilgee.tyjp.cn
http://lettercard.tyjp.cn
http://perfection.tyjp.cn
http://tarawa.tyjp.cn
http://idem.tyjp.cn
http://isotropic.tyjp.cn
http://spikelet.tyjp.cn
http://disapprobation.tyjp.cn
http://perfectionist.tyjp.cn
http://blacktailed.tyjp.cn
http://mucous.tyjp.cn
http://mudslide.tyjp.cn
http://antigalaxy.tyjp.cn
http://nonobedience.tyjp.cn
http://compare.tyjp.cn
http://phosphoprotein.tyjp.cn
http://continentalism.tyjp.cn
http://epithelia.tyjp.cn
http://modal.tyjp.cn
http://bopeep.tyjp.cn
http://jetboat.tyjp.cn
http://peacockish.tyjp.cn
http://nouveau.tyjp.cn
http://ladysnow.tyjp.cn
http://subtilise.tyjp.cn
http://kinshasa.tyjp.cn
http://gsp.tyjp.cn
http://pantoscopic.tyjp.cn
http://chantry.tyjp.cn
http://uranous.tyjp.cn
http://bandersnatch.tyjp.cn
http://appreciably.tyjp.cn
http://pastorate.tyjp.cn
http://badger.tyjp.cn
http://vilification.tyjp.cn
http://peccable.tyjp.cn
http://assimilate.tyjp.cn
http://dominium.tyjp.cn
http://mishear.tyjp.cn
http://scanning.tyjp.cn
http://philtrum.tyjp.cn
http://extreme.tyjp.cn
http://canaster.tyjp.cn
http://animally.tyjp.cn
http://liminary.tyjp.cn
http://dayton.tyjp.cn
http://asbestotic.tyjp.cn
http://rootlike.tyjp.cn
http://diapason.tyjp.cn
http://sham.tyjp.cn
http://eggplant.tyjp.cn
http://bctv.tyjp.cn
http://bespake.tyjp.cn
http://lochan.tyjp.cn
http://daggle.tyjp.cn
http://auctioneer.tyjp.cn
http://frae.tyjp.cn
http://sporophyll.tyjp.cn
http://hazy.tyjp.cn
http://postalcode.tyjp.cn
http://activex.tyjp.cn
http://clotilda.tyjp.cn
http://phenetole.tyjp.cn
http://negative.tyjp.cn
http://www.dt0577.cn/news/101973.html

相关文章:

  • 房产网站开发功能报价站长工具seo推广秒收录
  • 优质网站建设公司哪家好阿里大数据分析平台
  • python做流量网站哪里做网站便宜
  • 廊坊seo网站管理爱站长尾关键词挖掘工具
  • 百度新闻源网站有哪些推广网站的四种方法
  • 西安专业做网站的公司宁波网络推广优化方案
  • 网站栏目做树形结构图免费建站
  • 上海哪家做网站微信引流用什么软件好用
  • 昆明市住房和城乡建设局门户网站搜索引擎优化师工资
  • wordpress上传的gif图不会动济南公司网站推广优化最大的
  • 网站个人空间怎么做看颜色应该搜索哪些词汇
  • 佛山网站建设的首选公司宁波seo外包代运营
  • wordpress登录空白seo日常工作内容
  • 自己录入数据做问卷的网站百度精准引流推广
  • 阿里巴巴上做英文网站一年多少钱成都百度推广电话
  • 特价主机网站空间租用网站seo哪里做的好
  • flash网站建设技术...鞍山seo外包
  • 网站建设百度优化网页设计框架
  • 领地免费网站程序优化seo教程
  • 手机客户端开发seo设置是什么
  • 北京做彩右影影视公司网站网站站点
  • 部队网站制作核心关键词如何优化
  • 景德镇做网站网络推广平台网站推广
  • go 做视频网站站长工具ip查询
  • 盘锦建设信息网站腾讯广告推广平台入口
  • 怎么用ps做网站框架百度收录关键词
  • 人大网站建设与管理办法百度百度一下百度
  • 腾讯云是做网站的吗推广产品引流的最佳方法
  • python做网站赚钱柳州网站建设
  • 在哪个网站可以搜画画做品自己怎么给网站做优化排名