开发者社区> 问答> 正文

尝试上传一个文件名已被哈希到AWS S3 bucket

我试图上传一个文件到AWS S3,文件键是文件创建的日期,连接到文件本身的MD5散列。我没有问题产生哈希,但当试图上传文件,我得到以下错误。

botocore.exceptions.ClientError: An error occurred (InvalidURI) when calling the PutObject operation: Couldn't parse the specified URI.

我试图上传的文件是一个下载的网页。 这是我的代码

#new_page_content holds the downloaded html file I'm trying to upload.
new_page_content_encode("UTF-8") 
current_time = time.strftime("%Y_%m_%d_%H_%M_%S_", time.gmtime())
md5_hash_func = hashlib.md5()
md5_hash_func.update(new_page_content.encode("UTF-8"))
hashed_string = md5_hash_func.digest()
key_string = current_time + hashed_string

os.remove(LOCAL_PATH)
new_local_file = io.open(LOCAL_PATH, mode="w", encoding="utf-8")
new_local_file.write(new_page_content)
new_local_file.close()

#Uploading starts here
s3 = boto3.client(
        's3',
        aws_access_key_id=ACCESS_KEY,
        aws_secret_access_key=SECRET_KEY,
    )
data = open(LOCAL_PATH, "rb")
s3.upload_fileobj(data, BUCKET, key_string)
data.close()

我很确定问题是我使用了文档中定义的不安全的字母。我想知道是否有能力在上传文件时绕过它? 我曾遇到过类似的问题,但我不知道如何将解决方案转换为上传。 问题来源StackOverflow 地址:/questions/59378498/trying-to-upload-a-filename-that-has-been-hashed-to-aws-s3-bucket

展开
收起
kun坤 2019-12-30 10:33:18 1692 0
1 条回答
写回答
取消 提交回答
  • 解决了! 我使用hexdigest而不是digest来获得安全的字符。

    2019-12-30 10:33:24
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载