how to send form data in a programmatic file upload in box api 2.0

℡╲_俬逩灬. 提交于 2020-01-06 15:42:33

问题


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--

回答1:


Yes, that is the correct way to do it.




回答2:


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.




回答3:


-------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.



来源:https://stackoverflow.com/questions/10372708/how-to-send-form-data-in-a-programmatic-file-upload-in-box-api-2-0

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!