Dropbox API 工作正常,现在尝试使用 Carrierwave 将图像复制到 Amazon S3
我有一个 ipad 应用程序,它使用 dropbox 将图像同步到云端,以便我可以使用 web 应用程序访问它们并处理它们等等。
我遇到问题的部分是通过 Carrierwave 将文件从 dropbox 获取到 s3。我有一个照片模型,我可以创建一张新照片并成功上传图像。我还可以将文件放在保管箱上。但是,当我尝试从 dropbox 获取文件并将其放在 s3 上时,文件的内容只是文本。
我需要设置某种哑剧类型吗?
我正在使用 dropbox_sdk 和 get_file_and_metadata 方法。它成功返回文件对象,但内容只是文本。这是我对图像文件进行硬编码,以便我可以确定它存在。
dbsession = DropboxSession.deserialize(session[:dropbox_session])
@client = DropboxClient.new(dbsession, ACCESS_TYPE) #raise an exception if session not authorized
@info = @client.account_info # look up account information
@photo = Photo.new(params[:photo])
@db_image metadata = @client.get_file_and_metadata('/IMG_1575.jpg')
我不知道该怎么做的部分是说获取此图像 @db_image
并在创建新的 < 时使用该文件code>photo 并将其存储在 S3 上。
我认为这可能是一个“mime 类型”问题,但我读到这仅基于文件扩展名。
你们分享的任何见解都将真正帮助我克服这个障碍。谢谢!
I have an ipad app that uses dropbox to sync images to the cloud so that i can access them with a webapp and process them etc etc.
the part i'm having trouble with is getting the file from dropbox to s3 via carrierwave. i have a photo model and i can create a new photo and upload and an image successfully. I can also put a file on dropbox. However when i try to get a file off of dropbox and put it on s3, the contents of the file is just text.
Are there some sort of mime types i need to set or something?
I am using dropbox_sdk
and the get_file_and_metadata
method. It returns me the file object successfully, but the contents are all just text. this is me hard coding the image file so i can be sure it exists..
dbsession = DropboxSession.deserialize(session[:dropbox_session])
@client = DropboxClient.new(dbsession, ACCESS_TYPE) #raise an exception if session not authorized
@info = @client.account_info # look up account information
@photo = Photo.new(params[:photo])
@db_image metadata = @client.get_file_and_metadata('/IMG_1575.jpg')
the part i don't know how to do is say take this image @db_image
and use that file when creating a new photo
and store it on S3.
I'm thinking it might be a 'mime type' issue, but i've read that that is only based on the file ext.
any insight you guys could share would really help me get past this hurdle. thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了这一点。相反,我使用了
direct_url.url
方法,该方法是与carrierwave
gem 一起使用的dropbox-api
gem 的一部分。direct_url.url
方法返回该文件的安全完整 URL 路径,您可以将其用作 Carrierwave 的remote_url
值。现在,我对 ruby 还很陌生,所以我将发布一个更好的方法来逐步执行结果,因为这看起来相当缓慢且笨重。
Figured this out. Instead I used the
direct_url.url
method that is part of thedropbox-api
gem used with thecarrierwave
gem. thedirect_url.url
method returns a secure full url path to that file that you can use as theremote_url
value for carrierwave.Now, i'm pretty new at ruby, so i'll be posting a better way to step through the results, as that seems pretty slow and clunky.