保存在S3中的画面从临时网址画面、存在、网址

2023-09-11 23:41:13 作者:情兽

我正在开发在轨道上,用户可以上传图片由于在红宝石网站上的回形针,它存储在亚马逊S3 。之后,他们可以修改图片的感谢百鸟。但是,当我要保存新的图片,鸟舍,只是给了我一个临时的URL,我可以让我修改图片。

I am developing a website on ruby on rails where users can upload pictures thanks to paperclip, it is stored in amazon S3. After, they can modify pictures thanks to aviary. But when i want to save the new pictures, aviary just gave me an temporary URL where i can get my modified picture.

难道回形针能做到吗?我不认为它可以保存图片来自URL,并将其存储到S3?

Does paperclip can do it ? I don't think it can save an picture from an URL and store it to S3 ?

我搜索了一个星期了,我不知道这样做的最佳方式。我读过有关 filepicker ,但在S3文件中的帐户存储数据是不是免费的?

I've searched for a week now, and i don't know the best way to do it. I've read about filepicker, but the account to store data in S3 files isn't free ...

最后,我已经听说过此 S3 https://github.com/qoobaa / S3 ,但我不知道如何使用它。我已经安装了宝石S3,但是当我设置要求S3,它不承认。

Finally i've heard about this s3 https://github.com/qoobaa/s3, but i don't understand how to use it. I have installed gem s3, but when i set require 's3' , it is not recognize.

什么是最好的呢?

推荐答案

你为什么不传递百鸟生成到您的服务器的网址,并从那里上载新照片么?在code以下这是否在Python / Django的:

Why don't you pass the URL that Aviary generates to your server and upload the new photo from there? The code below does that in Python/Django:

@login_required    
@csrf_exempt
def upload_from_url(request):
    origin_url = request.POST.get("origin_url")
    name = request.POST.get("name")

    try:
        conn = boto.connect_s3(settings.AWS_ACCESS_KEY_ID, settings.AWS_SECRET_ACCESS_KEY)
        bucket_name = settings.AWS_UGC_STORAGE_BUCKET_NAME
        bucket = conn.get_bucket(bucket_name)
        k = Key(bucket)

        k.key = name   
        file_object = urllib2.urlopen(origin_url)
        fp = StringIO.StringIO(file_object.read())
        k.set_contents_from_file(fp)

        return HttpResponse("Success")
    except Exception, e:
        return HttpResponse(e, mimetype='application/javascript')

希望这有助于。

Hope this helps.