【问题标题】:How to create/write a text file instead of uploading to S3 bucket如何创建/写入文本文件而不是上传到 S3 存储桶
【发布时间】:2019-03-07 01:51:24
【问题描述】:

有没有一种方法可以在 AWS SDK 中向 S3 存储桶写入/创建文本文件?

【问题讨论】:

    标签: amazon-web-services amazon-s3 aws-php-sdk


    【解决方案1】:

    这可能会有所帮助。我使用 ZenS3 (https://github.com/cyberbuff/ZenS3)。它有一个 putObjectString() 方法。只需将字符串传递给 putObjectString 方法。它将在 S3 Bucket 中创建一个文件。确保您的存储桶应位于美国地区。

    【讨论】:

      【解决方案2】:

      Amazon S3 通过 HTTP REST API 工作。

      SDK 中有一些方法可以将字符串写入 S3 中的文件:例如 set_contents_from_string 方法。

      有不同的 S3 客户端可以为 S3 提供易用性,例如 CloudBerryDragonDisk

      【讨论】:

        【解决方案3】:

        可以使用AmazonS3.putObject() 的重载。 REST API 描述了here

        "content: The String to encode" 将按原样写入文件。 Word encode 可能有点混乱。

        /**
         * <p>
         * Encodes a String into the contents of an S3 object.
         * </p>
         * <p>
         * String will be encoded to bytes with UTF-8 encoding.
         * </p>
         *
         * @param bucketName
         *            The name of the bucket to place the new object in.
         * @param key
         *            The key of the object to create.
         * @param content
         *            The String to encode
         * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/s3-2006-03-01/PutObject">AWS API Documentation</a>
         */
        public PutObjectResult putObject(String bucketName, String key, String content)
                throws AmazonServiceException, SdkClientException;
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-04-25
          • 2021-10-20
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多