3

カスタム バックエンドを使用せずにファイルを S3 にアップロードしようとしています。これは私がこれまでに持っているものです:

conn=boto.connect_s3(settings.AWS_KEY, settings.AWS_SECRET)
bucket=conn.get_bucket(settings.AWS_BUCKET)
k = Key(bucket)

filename = f.name
keyname = str(int(uuid.uuid4()))[:10] + filename
k.key = keyname
k.set_contents_from_filename(f)
url = "https://s3.amazonaws.com/.../" + keyname

そして、次のエラーが表示されます。

TypeError at /qc/86/
coercing to Unicode: need string or buffer, InMemoryUploadedFile found

request['FILES']カスタムストレージバックエンドを使用せずに、s3からファイルを正しくアップロードするにはどうすればよいですか?

4

1 に答える 1

7

I faced a similar issue a while back instead of using set_contents_from_filename(f) try k.set_contents_from_string(f.read())

I did the same thing in this project here: https://github.com/buddylindsey/developerrage/blob/master/developerrage/comic/views.py

于 2012-08-06T22:46:43.580 に答える