栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Google Cloud Endpoints返回文件?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Google Cloud Endpoints返回文件?

这是将文件从端点保存到Cloud Storage并返回用于下载文件的URL的方法。

1 /在您的项目控制台中激活Google Cloud Storage

2 /在您的Cloud Storage实例中创建一个名称为bucketName的存储桶。可选:您可以在此存储桶上设置访问权限。

3 /在您的终结点类中,创建一个gcsService作为以下对象:

private final GcsService gcsService = GcsServiceFactory.createGcsService(new RetryParams.Builder()        .initialRetryDelayMillis(10)        .retryMaxAttempts(10)        .totalRetryPeriodMillis(15000)        .build());

4 /在您的方法中,创建一个ByteArrayOutputStream:

ByteArrayOutputStream os = new ByteArrayOutputStream();

5 /从ByteArrayOutputStream创建打印机

6 /然后执行以下操作:

ByteBuffer buf = ByteBuffer.wrap(os.toByteArray());GcsFilename gcsfileName = new GcsFilename(bucketName, bucketFileName);//bucketFileName =  your file nameGcsFileOptions options = new GcsFileOptions.Builder().mimeType("text/plain").build();GcsOutputChannel outputChannel = gcsService.createOrReplace(gcsfileName, options);outputChannel.write(buf);outputChannel.close();

7 /然后,您的文件应保存到Cloud
Storage:您只需要在字符串包装器中返回URL即可打开它。查看以下文档,以确定要使用的URL(取决于是否对用户进行身份验证,请参阅“授予用户对对象的读取权限”部分)https://cloud.google.com/storage/docs/云控制台#_访问



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/515734.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号