如何将字符串写入 Amazon S3 存储桶? [英] How to write a string to Amazon S3 bucket?

查看:43
本文介绍了如何将字符串写入 Amazon S3 存储桶?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 amazon s3 上添加字符串作为文件?从我搜索的任何内容中,我知道我们可以将文件上传到 s3.在不创建文件的情况下上传数据的最佳方法是什么?

解决方案

上传数据的最佳方式是什么不创建文件?

如果您的意思是不在 S3 上创建文件,那么,您真的不能这样做.在 Amazon S3 上,唯一存储数据的方式是作为文件,或者使用更准确的术语,对象.一个对象可以包含从 1 字节 零字节到 5 TB 的数据,并存储在 bucket 中.亚马逊的 S3 主页非常清楚地列出了基本事实.(对于 AWS 上的其他数据存储选项,您可能需要阅读例如关于 SimpleDB 的内容.)

如果您的意思是不创建本地临时文件,那么答案取决于您使用的库/工具.(正如 RickMeasham 建议的,请添加更多细节!)例如,使用 s3cmd 工具,您不能跳过创建临时文件,而使用 JetS3t Java 库直接上传字符串 会很容易:

//(首先初始化s3Service和testBucket)S3Object stringObject = new S3Object("HelloWorld.txt", "Hello World!");s3Service.putObject(testBucket, stringObject);

How can I add a string as a file on amazon s3? From whaterver I searched, I got to know that we can upload a file to s3. What is the best way to upload data without creating file?

解决方案

What is the best way to upload data without creating file?

If you meant without creating a file on S3, well, you can't really do that. On Amazon S3, the only way to store data is as files, or using more accurate terminology, objects. An object can contain from 1 byte zero bytes to 5 terabytes of data, and is stored in a bucket. Amazon's S3 homepage lays out the basic facts quite clearly. (For other data storing options on AWS, you might want to read e.g. about SimpleDB.)

If you meant without creating a local temporary file, then the answer depends on what library/tool you are using. (As RickMeasham suggested, please add more details!) With the s3cmd tool, for example, you can't skip creating temp file, while with the JetS3t Java library uploading a String directly would be easy:

// (First init s3Service and testBucket)
S3Object stringObject = new S3Object("HelloWorld.txt", "Hello World!");
s3Service.putObject(testBucket, stringObject);

这篇关于如何将字符串写入 Amazon S3 存储桶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆