上传文件到box api v2 [英] upload file to box api v2

查看:203
本文介绍了上传文件到box api v2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图上传一个文件到box.com与他们的V2 API。
我可以用curl成功上传文件,但不能从我的rails应用程序上传文件。我通过我的上传功能正确的文件夹ID和文件是一个临时文件对象创建的窗体上传在我的应用程序。

这里是成功的curl命令

  curl https://upload.box.com/api/2.0/files/data -H授权:BoxAuth api_key = API_KEY& auth_token = TOKEN-F contract=@test.png -F folder_id = 387656851 -ssl3 

这里是我的ruby代码

pre $ $ $

$ b $包括HTTMultiParty
ssl_version:SSLv3
$ b $ def初始化
@key = API_KEY
@token = TOKEN
结束
$ b $ def upload_file(folder_id,file,filename ,content_type)
File.open(file)do | open_file |
response = self.class.post('https://upload.box.com/2.0/files/data',:query => {
:file => open_file,
:folder_id => folder_id
},:headers => {'Authorization'=>BoxAuth api_key =#{key}& auth_token =#{@ token}})
p回应
end

end

我从这个文本框中得到一个html页面
看起来你的防火墙可能被阻塞了,或者你遇到了一个错误。

请联系你的IT管理员来配置你的防火墙识别.box.com,.box.com和.boxcdn.net的所有子域。应该为这些域打开的端口是80和443.

如果这不能解决问题,那么请在https://www.box.com/help提交支持票。



任何想法为什么curl命令将工作,而不是ruby代码?

解决方案

这适用于我

  require'httmultiparty'

类SomeClient
包括HTTMultiParty
base_uri'https://api.box.com/2.0'
结束

响应= SomeClient.post('/ files / data ',
:headers => {'authorization'=>'BoxAuth api_key = {YOUR API KEY}& auth_token = {YOUR TOKEN'},
:body => {:folder_id = >'0',:somefile => File.new('large.jpeg')}

我会尝试验证


  1. 您可以进行非上传API调用(即GET / folders / 0)

  2. 如果没有,请检查您的防火墙设置。


i am trying to upload a file to box.com with their v2 api. i am able to successfully upload a file with curl, but cannot upload a file from my rails application. i am passing my upload function the correct folder id and file is a tempfile object created by a form upload in my app.

here is the successful curl command

 curl https://upload.box.com/api/2.0/files/data -H "Authorization: BoxAuth api_key=API_KEY&auth_token=TOKEN" -F contract=@test.png -F folder_id=387656851 -ssl3

and here is my ruby code

class BoxApi

require 'httmultiparty'
include HTTMultiParty
ssl_version :SSLv3

def initialize
    @key = API_KEY
    @token = TOKEN
end

def upload_file(folder_id,file,filename,content_type)
    File.open(file) do |open_file|
        response = self.class.post('https://upload.box.com/2.0/files/data', :query => {
            :file => open_file,
            :folder_id => folder_id
            }, :headers => {'Authorization' => "BoxAuth api_key=#{@key}&auth_token=#{@token}"})
        p response
    end

end

i get an html page back from box with this text It appears that your firewall may be blocking Box or you are encountering an error.

Please contact your IT administrator to configure your firewall to recognize all sub-domains of .box.com, .box.com and .boxcdn.net. The ports that should be opened for these domains are 80 and 443.

If that does not resolve the issue, then please submit a support ticket at https://www.box.com/help.

any ideas why the curl command would be working but not the ruby code?

解决方案

This works properly for me

require 'httmultiparty'

class SomeClient
  include HTTMultiParty
  base_uri 'https://api.box.com/2.0'
end

response = SomeClient.post('/files/data', 
    :headers => { 'authorization' => 'BoxAuth api_key={YOUR API KEY}&auth_token={YOUR TOKEN' },
    :body => { :folder_id      => '0', :somefile => File.new('large.jpeg')}
)

I would try to verify that

  1. You can make non-upload API calls (i.e. GET /folders/0)
  2. If not, check your firewall settings.

这篇关于上传文件到box api v2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆