简体   繁体   English

AWS S3的getObject变得乱七八糟

[英]getObject from aws s3 got gibberish

in our project we have 1 service that uploads a local csv to s3, and I am working on another service which downloads csv that's uploaded using nodejs. 在我们的项目中,我们有1个将本地csv上传到s3的服务,而我正在开发另一个服务,该服务下载使用nodejs上传的csv。 I got gibberish in the content as i try to print the string of content (small csv). 当我尝试打印内容字符串(小型csv)时,内容出现乱码。 code : 代码:

 s3.getObject( { Bucket: mybucket, Key:mykey }, function(err,data){ console.log(data.Body.toString()) ; }) 

I have checked the data object that in the callback and found the type for buffer of data is unit8Array. 我检查了回调中的数据对象,发现数据缓冲区的类型为unit8Array。 I guess that's the cause. 我想这就是原因。 Does anyone know how I can control the type of buffer to be String? 有谁知道我如何控制缓冲区的类型为字符串? or is it something that needs to be changed during upload? 还是在上传过程中需要更改?

This is solved on the file upload side which is written in java. 这是在用Java编写的文件上传端解决的。 it was using AmazonS3EncryptionClientBuilder instead of AmazonS3ClientBuilder. 它使用的是AmazonS3EncryptionClientBuilder而不是AmazonS3ClientBuilder。 as a result data coming back when downloading is encrypted that's why its gibberish. 结果,下载时返回的数据被加密了,这就是其乱码的原因。 so it was not caused by buffer type 所以不是由缓冲区类型引起的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM