For some reason, the AWSS3HeadObjectOutput (always?) returns an empty object when trying to retrieve the metadata for an object. Why is that? Is there a way to ensure that the correct response is received?

I'm constructing my request as follows:
AWSS3 *s3Client = [AWSS3 defaultS3];
AWSS3HeadObjectRequest *request = [[AWSS3HeadObjectRequest alloc] init];
request.bucket = S3_BUCKET;
request.key = remoteUri;
return [s3Client headObject:request];
The metadata looks fine in the console.
P.S. I'm using the response to validate the existence and the recency of the uploaded data. If it's not correct, then I want to upload the correct version. With the ETag being null, it prevents me from doing this.
I was able to get ETag using the posted code snippet. You should share the entire code snippet and detail steps to reproduce the issue. (e.g. How you retrieved headOutput)
The problem is, I don't always get the ETag. Here's the code that calls it
[self check:photoMetadata[@"remoteUri"]] continueWithBlock:^id(AWSTask *task) {
if (task.error) {
if ([task.error.domain isEqualToString:AWSS3ErrorDomain]) {
switch (task.error.code) {
case AWSS3ErrorNoSuchKey:
return [self uploadToS3:url metadata:photoMetadata];
default:
break;
}
}
// throw the error back up, since we don't know what to do with it except to retry later
return task;
}
if (!task.result) {
return [self uploadToS3:url metadata:photoMetadata];
}
AWSS3HeadObjectOutput *headOutput = task.result;
NSLog(@"Head Output ETag: %@", headOutput.ETag);
if (!headOutput.ETag) {
return [self uploadToS3:url metadata:photoMetadata];
}
NSLog(@"Photo %@ already on S3.", photoMetadata[@"remoteUri"]);
// file already exists, so we no longer need to do anything else
return [AWSTask taskWithResult:nil];
}]
What is the ETag value returned by the service when headOutput has nil for ETag? You can enable the verbose logging by calling this method:
[AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose;
Then make a head request and look for "Response header" in the log.
Why was this issue closed? I am getting the same exact problem. I'm making a headObject request very similar to the above and I get an empty (not nil) task result returned. However many of the objects of the task are nil, contentLength (which im interested in getting) is nil. Various times the head request works, other times it doesnt. Ive checked my bucket and key parameter and they are fine so hmm :/ whats going on? The task is not returning an error at all, just an empty AWSS3HeadObjectOutput object.
You can enable the verbose logging by calling this method:
[AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose;
Then make head requests and look for the differences between the ones you get a response and the ones you don't.
None of my head requests get results. I enabled verbose logging and haven't gotten anything useful; there are no error messages related to the head requests.
How do I debug? I have the same use case as the OP.
In the log, what does it print after "Response header: "?
@rrroni Just out of curiosity, when do you try to make a HEAD request? Do you do it right after uploading the resource? Also, is your resource publicly accessible? If so, what is the result of a curl -X HEAD request?
Was this solved and if so how? I'm encountering a similar issue, not getting any metadata in return for my HEAD requests.
@bvirlet This was not solved. I'm wondering if it has something to do with eventual consistency and the high latency of S3. Did you eventually get metadata from the requests after waiting some time after adding?
Most helpful comment
Why was this issue closed? I am getting the same exact problem. I'm making a headObject request very similar to the above and I get an empty (not nil) task result returned. However many of the objects of the task are nil, contentLength (which im interested in getting) is nil. Various times the head request works, other times it doesnt. Ive checked my bucket and key parameter and they are fine so hmm :/ whats going on? The task is not returning an error at all, just an empty AWSS3HeadObjectOutput object.