下面的代码块有效,但我想取消注释filename = os.path.basename(filename),当我这样做时,我无法指定文件名的绝对路径,因为k.set_contents_from_filename将不再引用实际的位置如果未注释,则只有当前工作目录中的文件才能正常工作.如果我不使用filename = os.path.basename(filename),那么文件将上传其路径预先填写.有任何想法吗?
# List files in directory and upload them to bucket
for filename in all_files:
#skip all directory entries which are not a file
if not os.path.isfile(filename):
continue
#filename = os.path.basename(filename)
k = Key(bucket)
k.key = filename
k.set_contents_from_filename(filename, cb=percent_cb, num_cb=10)
解决方法:
除非我完全遗漏某些东西,为什么你不能做这样的事情呢?
# List files in directory and upload them to bucket
for filename in all_files:
#skip all directory entries which are not a file
if not os.path.isfile(filename):
continue
k = Key(bucket)
k.key = os.path.basename(filename)
k.set_contents_from_filename(filename, cb=percent_cb, num_cb=10)
标签:python,scripting
来源: https://codeday.me/bug/20190827/1736712.html