Uploads a file to a destination (parent) folder. The BOX_FOLDER_ID should be replaced with the id of the folder, or 0 for the root folder.
curl https://upload.box.com/api/2.0/files/content \
-H "Authorization: Bearer BOX_ACCESS_TOKEN" -X POST \
-F attributes='{"name":"tigers.jpeg", "parent":{"id":"BOX_FOLDER_ID"}}' \
-F file=@tigers.jpeg
LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loFileStream2
LOCAL lcStrResponseBody
LOCAL loJsonResponse
LOCAL lnTotal_count
LOCAL i
LOCAL lnCount_i
LOCAL lcType
LOCAL lcId
LOCAL lcSequence_id
LOCAL lcEtag
LOCAL lcSha1
LOCAL lcName
LOCAL lcDescription
LOCAL lnSize
LOCAL lnPath_collectionTotal_count
LOCAL lcCreated_at
LOCAL lcModified_at
LOCAL lnTrashed_at
LOCAL lnPurged_at
LOCAL lcContent_created_at
LOCAL lcContent_modified_at
LOCAL lcCreated_byType
LOCAL lcCreated_byId
LOCAL lcCreated_byName
LOCAL lcCreated_byLogin
LOCAL lcModified_byType
LOCAL lcModified_byId
LOCAL lcModified_byName
LOCAL lcModified_byLogin
LOCAL lcOwned_byType
LOCAL lcOwned_byId
LOCAL lcOwned_byName
LOCAL lcOwned_byLogin
LOCAL lnShared_link
LOCAL lcParentType
LOCAL lcParentId
LOCAL lcParentSequence_id
LOCAL lcParentEtag
LOCAL lcParentName
LOCAL lcItem_status
LOCAL j
LOCAL lnCount_j
LOCAL lnSequence_id_bool
LOCAL lnEtag_bool
loRest = CreateObject('Chilkat_9_5_0.Rest')
* URL: https://upload.box.com/api/2.0/files/content
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("upload.box.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
loRest.PartSelector = "1"
loRest.AddHeader("Content-Disposition",'form-data; name="attributes"')
loRest.SetMultipartBodyString('{"name":"tigers.jpeg", "parent":{"id":"BOX_FOLDER_ID"}}')
loRest.PartSelector = "2"
loFileStream2 = CreateObject('Chilkat_9_5_0.Stream')
loFileStream2.SourceFile = "tigers.jpeg"
loRest.AddHeader("Content-Disposition",'form-data; name="tigers.jpeg"; filename="tigers.jpeg"')
loRest.AddHeader("Content-Type","image/jpeg")
loRest.SetMultipartBodyStream(loFileStream2)
loRest.PartSelector = "0"
loRest.AddHeader("Authorization","Bearer BOX_ACCESS_TOKEN")
loRest.PartSelector = "0"
loRest.AddHeader("Content-Type","multipart/form-data")
lcStrResponseBody = loRest.FullRequestMultipart("POST","/api/2.0/files/content")
IF (loRest.LastMethodSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loFileStream2
CANCEL
ENDIF
loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.Load(lcStrResponseBody)
lnTotal_count = loJsonResponse.IntOf("total_count")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("entries")
DO WHILE i < lnCount_i
loJsonResponse.I = i
lcType = loJsonResponse.StringOf("entries[i].type")
lcId = loJsonResponse.StringOf("entries[i].id")
lcSequence_id = loJsonResponse.StringOf("entries[i].sequence_id")
lcEtag = loJsonResponse.StringOf("entries[i].etag")
lcSha1 = loJsonResponse.StringOf("entries[i].sha1")
lcName = loJsonResponse.StringOf("entries[i].name")
lcDescription = loJsonResponse.StringOf("entries[i].description")
lnSize = loJsonResponse.IntOf("entries[i].size")
lnPath_collectionTotal_count = loJsonResponse.IntOf("entries[i].path_collection.total_count")
lcCreated_at = loJsonResponse.StringOf("entries[i].created_at")
lcModified_at = loJsonResponse.StringOf("entries[i].modified_at")
lnTrashed_at = loJsonResponse.IsNullOf("entries[i].trashed_at")
lnPurged_at = loJsonResponse.IsNullOf("entries[i].purged_at")
lcContent_created_at = loJsonResponse.StringOf("entries[i].content_created_at")
lcContent_modified_at = loJsonResponse.StringOf("entries[i].content_modified_at")
lcCreated_byType = loJsonResponse.StringOf("entries[i].created_by.type")
lcCreated_byId = loJsonResponse.StringOf("entries[i].created_by.id")
lcCreated_byName = loJsonResponse.StringOf("entries[i].created_by.name")
lcCreated_byLogin = loJsonResponse.StringOf("entries[i].created_by.login")
lcModified_byType = loJsonResponse.StringOf("entries[i].modified_by.type")
lcModified_byId = loJsonResponse.StringOf("entries[i].modified_by.id")
lcModified_byName = loJsonResponse.StringOf("entries[i].modified_by.name")
lcModified_byLogin = loJsonResponse.StringOf("entries[i].modified_by.login")
lcOwned_byType = loJsonResponse.StringOf("entries[i].owned_by.type")
lcOwned_byId = loJsonResponse.StringOf("entries[i].owned_by.id")
lcOwned_byName = loJsonResponse.StringOf("entries[i].owned_by.name")
lcOwned_byLogin = loJsonResponse.StringOf("entries[i].owned_by.login")
lnShared_link = loJsonResponse.IsNullOf("entries[i].shared_link")
lcParentType = loJsonResponse.StringOf("entries[i].parent.type")
lcParentId = loJsonResponse.StringOf("entries[i].parent.id")
lcParentSequence_id = loJsonResponse.StringOf("entries[i].parent.sequence_id")
lcParentEtag = loJsonResponse.StringOf("entries[i].parent.etag")
lcParentName = loJsonResponse.StringOf("entries[i].parent.name")
lcItem_status = loJsonResponse.StringOf("entries[i].item_status")
j = 0
lnCount_j = loJsonResponse.SizeOfArray("entries[i].path_collection.entries")
DO WHILE j < lnCount_j
loJsonResponse.J = j
lcType = loJsonResponse.StringOf("entries[i].path_collection.entries[j].type")
lcId = loJsonResponse.StringOf("entries[i].path_collection.entries[j].id")
lnSequence_id_bool = loJsonResponse.IsNullOf("entries[i].path_collection.entries[j].sequence_id")
lnEtag_bool = loJsonResponse.IsNullOf("entries[i].path_collection.entries[j].etag")
lcName = loJsonResponse.StringOf("entries[i].path_collection.entries[j].name")
j = j + 1
ENDDO
i = i + 1
ENDDO
RELEASE loRest
RELEASE loFileStream2
RELEASE loJsonResponse
{
"total_count": 1,
"entries": [
{
"type": "file",
"id": "5000948880",
"sequence_id": "3",
"etag": "3",
"sha1": "134b65991ed521fcfe4724b7d814ab8ded5185dc",
"name": "tigers.jpeg",
"description": "a picture of tigers",
"size": 629644,
"path_collection": {
"total_count": 2,
"entries": [
{
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
},
{
"type": "folder",
"id": "11446498",
"sequence_id": "1",
"etag": "1",
"name": "Pictures"
}
]
},
"created_at": "2012-12-12T10:55:30-08:00",
"modified_at": "2012-12-12T11:04:26-08:00",
"trashed_at": null,
"purged_at": null,
"content_created_at": "2013-02-04T16:57:52-08:00",
"content_modified_at": "2013-02-04T16:57:52-08:00",
"created_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"modified_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"owned_by": {
"type": "user",
"id": "17738362",
"name": "sean rose",
"login": "sean@box.com"
},
"shared_link": null,
"parent": {
"type": "folder",
"id": "11446498",
"sequence_id": "1",
"etag": "1",
"name": "Pictures"
},
"item_status": "active"
}
]
}