Hello,
I am trying to upload a document but am receiving error 400 (API upload did not contain a file part).
I have to use an application called 4D to submit the http request using the following code…
$boundary:=Generate UUID
$crlf:="\r\n"
$bodyPartTxt:=""
$bodyPartTxt:=$bodyPartTxt+"--"+$boundary+$crlf
$bodyPartTxt:=$bodyPartTxt+"Content-Disposition: form-data; name=\"attributes\""+$crlf
$bodyPartTxt:=$bodyPartTxt+"Content-Type: application/json"+$crlf+$crlf
$bodyPartTxt:=$bodyPartTxt+$attributesText+$crlf
$bodyPartTxt:=$bodyPartTxt+"--"+$boundary+$crlf
$bodyPartTxt:=$bodyPartTxt+"Content-Disposition: form-data; name=\"file\"; filename=\""+$docName+"\""+$crlf
$bodyPartTxt:=$bodyPartTxt+"Content-Type: text/plain"+$crlf
$bodyPartTxt:=$bodyPartTxt+"Some text."+$crlf
$bodyPartTxt:=$bodyPartTxt+"--"+$boundary+"--"
ARRAY TEXT(aHeaderNames; 0)
ARRAY TEXT(aHeaderValues; 0)
APPEND TO ARRAY(aHeaderNames; "authorization")
APPEND TO ARRAY(aHeaderValues; "bearer "+$boxToken)
APPEND TO ARRAY(aHeaderNames; "as-user")
APPEND TO ARRAY(aHeaderValues; <>BoxUserID)
APPEND TO ARRAY(aHeaderNames; "Content-length")
APPEND TO ARRAY(aHeaderValues; String(Length($bodyPartTxt)))
APPEND TO ARRAY(aHeaderNames; "Content-type")
APPEND TO ARRAY(aHeaderValues; "multipart/form-data; boundary="+$boundary)
$url:="https://upload.box.com/api/2.0/files/content"
$statusCode:=HTTP Request(HTTP POST method; $url; $bodyPartTxt; $responseTxt; aHeaderNames; aHeaderValues; *)
The contents sent in $bodyPartTxt are…
--0C70A9C683B34506B5224BE1EC4AF89E\r\nContent-Disposition: form-data; name="attributes"\r\nContent-Type: application/json\r\n\r\n{"name":"JimTest01.txt","parent":{"id":"309964342881"}}\r\n--0C70A9C683B34506B5224BE1EC4AF89E\r\nContent-Disposition: form-data; name="file"; filename="JimTest01.txt"\r\nContent-Type: text/plain\r\nSome text.\r\n--0C70A9C683B34506B5224BE1EC4AF89E--
I receive the following error…
{"code":"bad_request","help_url":"http://developers.box.com/docs/#errors","status":400,"message":"API upload did not contain a file part","type":"error"}
I’ve tried several changes…
- Put the text in a blob and send that instead of text.
- base 64 encode the text of the document.
- Changing the number or location of $crlf. This resulted in errors such as malformed stream, unexpected end of stream, or no response text at all.
I’d appreciate any ideas. I’m stumped!