Premise · What I want to realize
I'm trying to download file in Box via Box API, but I get a 404 error every time.
Testing environment
- Box Java SDK 2.24.0
- Scala 2.11.8
- sbt 0.13.13
What I did
Write a code
class BoxFileDownload extends ApiActor with ActorLogging {
def receive: PartialFunction[Any, Unit] = {
case _event: HttpRequestEvent => implicit val event: HttpRequestEvent = _event
// Load the configuration file of the BOX application
val reader = new FileReader(".../box/config.json")
val boxConfig = BoxConfig.readFrom(reader)
// Set a cache information
val MAX_CACHE_ENTRIES = 100
val accessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES)
// Generate an enterprise connection object of Box Application
val client = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, accessTokenCache)
// Download the Box file
val boxFileId = event.endPoint.getQueryString("box_file_id").getOrElse(0)
val file = new BoxFile(client, boxFileId.toString)
val info = file.getInfo()
val stream = new FileOutputStream(info.getName)
file.download(stream)
stream.close()
}
}
Problems occurring · Error messages
When you execute the above code, ...
com.box.sdk.BoxAPIResponseException: The API returned an error code [404 | 7g59i4fxq8w0vd3r] not_found - Not Found
at com.box.sdk.BoxAPIResponse.(BoxAPIResponse.java:92)
at com.box.sdk.BoxJSONResponse.(BoxJSONResponse.java:32)
at com.box.sdk.BoxAPIRequest.trySend(BoxAPIRequest.java:579)
at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:354)
at com.box.sdk.BoxAPIRequest.send(BoxAPIRequest.java:329)
at com.box.sdk.BoxFile.getInfo(BoxFile.java:452)
at jp.co.dac.advr.planning_web.controllers.menu.BoxFileDownload$$anonfun$receive$2.applyOrElse(Index.scala:81) = this line: val info = file.getInfo()I got an errors. What shoud I do? Could you lend me a hand?
Thank you for reading.

