简体   繁体   中英

Reading an Amazon S3 log file

So I am having problems reading anything from a bucket

I know I am connecting fine as I am getting a listing of the bucket contents, I retrieve the key and I am trying to use it as such

foreach (var log in logs.Select(q => q.logFile).ToList())
        {
    var getObjectRequest = new GetObjectRequest().WithBucketName(bucketName).WithKey(log);
    var getObjectResponse = new GetObjectResponse();

    StreamReader reader = new StreamReader(getObjectResponse.ResponseStream);
    String content = reader.ReadToEnd();
}

I get back

Value cannot be null. Parameter name: stream

on

StreamReader reader = new StreamReader(getObjectResponse.ResponseStream);

Thanks in advance!

Your getObjectResponse is setup incorrectly. You are simply creating a new GetObjectResponse . It is not hooked up to getObjectRequest .

Change

var getObjectResponse = new GetObjectResponse();

to

var getObjectResponse = client.GetObject(getObjectRequest);

where client is your S3 client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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