2015-01-02 7 views
0

여기에 특정 폴더에 파일을 업로드 내 박스 업로드 POST입니다 :HTTP 500

POST /api/2.0/files/content HTTP/1.1 
Authorization: Bearer ACCESS_TOKEN 
Accept: application/json 
User-Agent: SOASoftware/7-HttpCore/4 
Transfer-Encoding: chunked 
Content-Type: multipart/form-data 
Host: upload.box.com 
Connection: Keep-Alive 

attributes='{"name":"lead.txt", "parent":{"id":"2890481033"}}'&file=C:\SOA\Software\sm70\instances\nd\leads.txt 
-----------------------------9051914041544843365972754266 
<file-data> 
-----------------------------9051914041544843365972754266 

는하지만이 응답을, 나에게 도움이되지 않는 어떤 문제를 이해하기 다음과 같습니다 :

HTTP/1.1 500 
Age: 0 
Date: Fri, 02 Jan 2015 09:06:09 GMT 
Connection: close 

EMPTY MESSAGE 

HTTP 500을 일으키는 요청에서 내가 뭘 잘못하고 있는지 말해 줄 수 있습니까?

답변

0

멀티 파트 요청의 형식이 잘못 지정된 것 같습니다. 이를 수행하는 가장 쉬운 방법은 use an SDK입니다. 또는 다중 요청을 작성할 수있는 라이브러리를 찾을 수 있습니다.

POST https://upload.box.com/api/2.0/files/content HTTP/1.1 
Host: upload.box.com 
Authorization: Bearer ACCESS_TOKEN 
Content-Length: 346 
Content-Type: multipart/form-data; boundary=------------------------393329c2f2238ab4 

--------------------------393329c2f2238ab4 
Content-Disposition: form-data; name="attributes" 

{"name":"my-file.txt", "parent":{"id":"0"}} 
--------------------------393329c2f2238ab4 
Content-Disposition: form-data; name="file"; filename="my-file.txt" 
Content-Type: application/octet-stream 

<file-data> 

--------------------------393329c2f2238ab4-- 
+0

감사 그렉 :

당신이 정말로 요청을 수동으로 구축하려는 경우, 여기에 업로드 요청이 어떻게 보일지의 예! 내 솔루션은 손으로 몸을 크랭크를 기반으로하기 때문에 도서관을 찾아 볼 것이므로 올바른 몸체를 보내도록 수정하지 않아도됩니다. SDK가 도움이되지 않도록 자바 스크립트를 사용하고 있습니다. –

+0

그렉, 좀 더 테스트를하고 Content-Type 헤더에 boundary 매개 변수를 추가하면 BOX API에서 http 400 (잘못된 요청)이 발생합니다. 해당 매개 변수를 제거하면 위와 같이 서식을 지정할 때 500이됩니다. Box API 사용자가 필요합니다. –

+0

위의 예에서 파일을 성공적으로 업로드해야합니다. 요청이 올바른 Content-Length, Content-Disposition 및 Content-Type 헤더로 올바르게 형식화되어 있는지 확인하십시오. [API 문서] (https://developers.box.com/docs/#files-upload-a-file)에는 업로드를 테스트하는 데 사용할 수있는 cURL 스 니펫이 있습니다. – Greg