how to send form data in a programmatic file uploa

2019-08-16 14:58发布

Is the following a correct example of the form POST data in a file upload in the box api 2.0? The documentation says that the 'filename' form field is a string but when sending the post data in, say, python, you need to actually send the file contents in the post. So, is the content-disposition: form-data line below the correct way to name the 'filename' field and include the file contents?

Content-type: multipart/form-data, boundary=AaB03x
Content-length: 142
Authorization: BoxAuth api_key=MY_API_KEY&auth_token=MY_AUTH_TOKEN

--AaB03x
content-disposition: form-data; name="filename"; filename="test.txt"
Content-type: text/plain

testing box api 2.0

--AaB03x--

标签: box-api
3条回答
Anthone
2楼-- · 2019-08-16 15:35
-------boundary
Content-Disposition: form-data; name="filename"; filename="82b.gif"
Content-Type: image/gif
Content-Transfer-Encoding: BASE64

$base64_encoded_binary_file_content
-------boundary
Content-Disposition: form-data; name="parent_id"

123456789
-------boundary--

This is working code.

查看更多
老娘就宠你
3楼-- · 2019-08-16 15:41

Yes, that is the correct way to do it.

查看更多
你好瞎i
4楼-- · 2019-08-16 15:53

You mention Python, although you don't mention as being a requirement. If you can use Ruby (another scripting language) you have a very nice lib to deal with Box API at the 2.0 version.

The lib is named ruby-box and in the readme you can find how to use it.

查看更多
登录 后发表回答