2

我在尝试使用FileUpload API将文件上传到Stripe时出现问题。我已经实施了CarrierWave S3来在我的网站上上传文件。我已经遵循了所有的Stripe API文档,但由于某种原因,它给了我一个“没有这样的文件或目录@ rb_sysopen”的错误。Rails,Stripe,CarrierWave,FileUpload,没有这样的文件

这里是上传我的控制器代码:

@id_upload = Stripe::FileUpload.create(
    :purpose => 'identity_document', 
    :file => File.new(@user.uploaded_file.url) 
) 

这将返回“没有这样的文件”的错误,与S3链接( - https://myapp.s3.amazonaws.com/uploads/user/uploaded_file/1/file.png)。有趣的是,当我在浏览器中访问该链接时,上传的文件存在,并显示出来。

有什么想法?我错过了明显的东西吗?

谢谢!

+0

你让它工作? @gitastic –

回答

0

我无法直接从Amazon S3获取文件到Striple File Upload。但是,我按照下面的链接下载亚马逊的资源,首先从Amazon S3下载文件到Web服务器,然后将其发送到条纹: https://aws.amazon.com/blogs/developer/downloading-objects-from-amazon-s3-using-the-aws-sdk-for-ruby/

的Gemfile:

gem 'aws-sdk', '~> 2' 

在您的客户端:

s3 = Aws::S3::Client.new 
    resp = s3.get_object({ bucket:'your-bucket-name', key: current_user.stripe_managed_account.personal_id_document.file.path }, 
    target: '/tmp/personal_id_file_#{current_user.id}') 

    stripe_file_upload = 
     Stripe::FileUpload.create(
     :purpose => 'identity_document', 
     :file => File.new('/tmp/personal_id_file_#{current_user.id}') 
    ) 

    account ||= Stripe::Account.retrieve(current_user.stripe_managed_account.stripe_account_id) 
    account.legal_entity.verification.document = stripe_file_upload.id 
    account.save 
相关问题