An exception “The Content-MD5 you specified did not match what we received”

后端 未结 5 1576
谎友^
谎友^ 2021-01-17 17:14

I got an exception, I never got before when testing my application that uploads a file from ec2 to s3. The content is:

Exception in thread \"Thread-1\" com.a         


        
5条回答
  •  悲&欢浪女
    2021-01-17 17:43

    Another reason for having this issue is to run a code such as this (python)

    with open(filename, 'r') as fd:
         self._bucket1.put_object(Key=key, Body=fd)
         self._bucket2.put_object(Key=key, Body=fd)
    

    In this case the file object (fd) is pointing to the end of the file when it reaches line 3, so we will get the "Content MD5" error, in order to avoid it we will need to point the file reader back to the start position in the file

    with open(filename, 'r') as fd:
         bucket1.put_object(Key=key, Body=fd)
         fd.seek(0)
         bucket2.put_object(Key=key, Body=fd)
    

    This way we won't get the aforementioned Boto error.

提交回复
热议问题