在html中显示AWS BOTO上传状态

时间:2015-05-15 08:13:55

标签: django angularjs amazon-web-services amazon-s3

我正在使用Django和Angular js。我使用BOTO在s3上传照片。如何使用django获取上传状态并使用angular js显示它?

我有这个功能:

def percent_cb(complete, total):
    print '%d bytes transferred out of %d' % (complete, total)


def upload_to_s3(project_file):
    sourceDir = photos_folder + project_file +'/'
    destDir = '/photos/'+ project_file +'/'
    MAX_SIZE = 20 * 1000 * 1000
    PART_SIZE = 6 * 1000 * 1000

    conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY_SECRET)
    bucket = conn.get_bucket(bucket_name)

    k = boto.s3.key.Key(bucket)
    k.key = destpat
    k.set_contents_from_filename(sourcepath, cb=percent_cb, num_cb=10)

我上传示例照片时的日志:

0 bytes transferred out of 508450
57344 bytes transferred out of 508450
114688 bytes transferred out of 508450
172032 bytes transferred out of 508450
229376 bytes transferred out of 508450
286720 bytes transferred out of 508450
344064 bytes transferred out of 508450
401408 bytes transferred out of 508450
458752 bytes transferred out of 508450
508450 bytes transferred out of 508450

我想在每次打印时输出percent_cb并将其传递给角度为html显示..

他们有什么办法吗?

  • 感谢

0 个答案:

没有答案