3

I'm trying to copy an object from one folder to another folder in my S3 bucket. I'm using copyObject to achieve that goal.

After looking at the documentation PUT Object — Copy, I’m doing a request where I’m sending the following params:

{ 
    Bucket: 'bucket-name',
    CopySource: 'bucket-name/Desarrollo/1/Fraccionamiento/3/Vivienda/101/Acuse%20Vendedores.pdf',
    Key: 'Expedientes/2017/Queretaro/Febrero/226/Acuse%20Vendedores.pdf',
    ACL: 'public-read' 
}

However, I keep getting this error back:

NoSuchKey: The specified key does not exist

Not sure what I’m doing wrong. The error says that no such key exists. In my params the Key clearly does not exist, because that is where I want the new object to be copied to. I’ve even tried manually creating the new target folder beforehand. As far as I understand the documentation that I mention above, the key is the target. What value should I put for the key?

TRiG
  • 10,148
  • 7
  • 57
  • 107
Moises
  • 53
  • 1
  • 6
  • If my object in a folder. so how can I update the CacheControl of the existing object? I have try this but get error like : The specified key does not exist $response = $OBJ_aws_s3->copyObject(array( 'Bucket' => $bucket, 'Key' => $key, 'CopySource' => urlencode($bucket .'/'. $foldername. '/' . $key), 'CacheControl' => 'max-age=94608000', 'MetadataDirective' => 'REPLACE', )); – Bhargav Variya May 26 '21 at 11:07

1 Answers1

0

Is Acuse%20Vendedores really what you're trying to copy? That looks URL escaped maybe.

nobody
  • 7,803
  • 11
  • 56
  • 91
  • that is the file Key I get from AWS after I upload the file to S3. So yes that is what I'm trying to copy. AWS S3 escapes the key name. – Moises May 25 '17 at 01:32
  • according to this answer https://stackoverflow.com/questions/28653249/android-amazon-s3-exception-the-specified-key-does-not-exist it seems symbols cause problems for s3 – nobody May 25 '17 at 04:07
  • %20 escapes from a space character so i assume it is something similar – nobody May 25 '17 at 04:07
  • 1
    I think you are into something, I just assumed the key name was right because that is the key name I get back from S3 and the object's link is escaped and it works. I'll check and report back. Thanks! – Moises May 25 '17 at 15:24
  • 1
    you were right it had to do with the escaped empty space `%20`. So now before I upload to S3 look out for the characters to avoid mentioned in the link you posted. After that I don't get the `NoSuchKey` error anymore and the object is copied correctly into the new folder. – Moises May 25 '17 at 21:53
  • If my object in a folder. so how can I update the CacheControl of the existing object? I have try this but get error like : The specified key does not exist $response = $OBJ_aws_s3->copyObject(array( 'Bucket' => $bucket, 'Key' => $key, 'CopySource' => urlencode($bucket .'/'. $foldername. '/' . $key), 'CacheControl' => 'max-age=94608000', 'MetadataDirective' => 'REPLACE', )); – Bhargav Variya May 26 '21 at 11:06