AWS: how to fix S3 event replacing space with '+' sign in object key names in json

后端 未结 7 1381
名媛妹妹
名媛妹妹 2020-12-31 00:23

I have a lamba function to copy objects from bucket \'A\' to bucket \'B\', and everything was working fine, until and object with name \'New Text Document.txt\' was created

相关标签:
7条回答
  • 2020-12-31 01:14

    I came across this looking for a solution for a lambda written in python instead of java; "urllib.parse.unquote_plus" worked for me, it properly handled a file with both spaces and + signs:

    from urllib.parse import unquote_plus
    import boto3
    
    
    bucket = 'testBucket1234'
    # uploaded file with name 'foo + bar.txt' for test, s3 Put event passes following encoded object_key
    object_key = 'foo %2B bar.txt'
    print(object_key)
    object_key = unquote_plus(object_key)
    print(object_key)
    
    client = boto3.client('s3')
    client.get_object(Bucket=bucket, Key=object_key)
    
    0 讨论(0)
提交回复
热议问题