问题
I am using AWS PHP SDK. I uploaded a JSON file to S3 bucket. Now I would like to get the file contents(uploaded to S3 bucket), add some additional text to the grabbed file contents and update that file over the S3 bucket.
What I want is something like this:
- file name:
userlist.json
- grab content of file using S3 provide methods
- eg: existing file contents are
{'abc','xyz'}
- add additional contents
{'abc','xyz'}, {'zxv','opiv','cvpo'}
- update newly added content into S3 bucket file (
userlist.json
)
How we can do this ?
回答1:
You can't add data to, or modify just part of an existing s3 object, you need to read the object, make changes to the object, and the write the entire object back to s3.
回答2:
You can overwrite any file in s3. When you write file in same location with same name then it remove old file and replace it with new one.
回答3:
You can follow the following algorithm
step 1 : get the file content from a specific bucket using the function
return $result = $this->s3->getObject(array(
'Bucket' => bucket,
'Key' => 'file_name'
));
step 2: Write the return content in a local file.
step 3: Read the file and modify whatever you like. Save the file in local machine. Here you can save the file in different extension.
step 4: Upload the file in the desired bucket. Remember it s3 bucket shall not give immediate update if you overwrite the file with same name.
step 5:End
来源:https://stackoverflow.com/questions/34761076/can-we-update-contents-of-a-specific-file-in-amazon-s3