Overwrite upload of file with the same name with BOX SDK (java)

BoxFolder.uploadFile causes an error if a file with the same name already exists

I wish I had an overwrite option ...

//Upload file to root folder
BoxFile.Info newFileInfo = null;
try (FileInputStream stream = new FileInputStream("C:\\hoge\\updload_sample.txt")) {
  newFileInfo = rootFolder.uploadFile(stream, fileName);
} catch (BoxAPIResponseException e) {
  System.out.println("LocalizedMessage : " + e.getLocalizedMessage());
  //If a file with the same name already exists
  if (e.getLocalizedMessage().contains("409")) {
   //Search for the corresponding file
    Iterator<Info> ite = rootFolder.getChildren().iterator();
    while (ite.hasNext()) {
      Info boxInfo = (Info)ite.next();
      String objectName = boxInfo.getName();
      if(objectName.equals(fileName)) {
        String fileId = boxInfo.getID();
        BoxFile file = new BoxFile(api, fileId);
     //upload
        try (FileInputStream stream = new FileInputStream("C:\\hoge\\updload_sample.txt")) {
          file.uploadVersion(stream);
        }
      }
    }
  }
}

Task

BoxFile.uploadVersion has been deprecated, but I couldn't find any other alternative. ..

Recommended Posts

Overwrite upload of file with the same name with BOX SDK (java)
[Java] Get MimeType from the contents of the file with Apathce Tika [Kotlin]
JAVA: jar, aar, view the contents of the file
[JAVA] Get only the file name, excluding the extension
Rename the package name of the existing jar file
Calculate the similarity score of strings with JAVA
Import files of the same hierarchy in Java
<Java> Quiz to batch convert file names separated by a specific character string with a part of the file name
[Java] Check the JDK version of the built war file
[Java] How to extract the file name from the path
Test the contents of an Excel file with JUnit
Monitor the internal state of Java programs with Kubernetes
[Java] Get the file in the jar regardless of the environment
[Java] Get the file path in the folder with List
The story of making dto, dao-like with java, sqlite
Form and process file and String data at the same time with Spring Boot + Java
Java desktop with the same front end as the WEB.
Replace only part of the URL host with java
[Java] Simplify the implementation of data history management with Reladomo
Ruby / rexml: Turn each with an element with the same name
About the behavior when doing a file map with java
Be sure to compare the result of Java compareTo with 0
How to change the file name with Xcode (Refactor Rename)
iOS: File upload with SFTP
File upload with Spring Boot
[Java1.8 +] Get the date of the next x day of the week with LocalDate
Try Hello World with the minimum configuration of Heroku Java spring-boot
Fix the file name of war to the one set in Maven
A story about hitting the League Of Legends API with JAVA
Get the public URL of a private Flickr file in Java
Read the first 4 bytes of the Java class file and output CAFEBABE
The point of addiction when performing basic authentication with Java URLConnection
[Java] Returns a Japanese name file in filename of HTTP header
Is the version of Elasticsearch you are using compatible with Java 11?
How to get the length of an audio file in java
How to realize huge file upload with Rest Template of Spring
[Java] Delete the elements of List
Replace the contents of the Jar file
[Java version] The story of serialization
Upload a file using Java HttpURLConnection
Unzip the zip file in Java
Follow the link with Selenium (Java)
EXCEL file update sample with JAVA
The origin of Java lambda expressions
Remote debugging of the Cognos SDK
For the time being, run the war file delivered in Java with Docker
The story of forgetting to close a file in Java and failing
The story of making a game launcher with automatic loading function [Java]
Email sent by JavaMail Gmail cannot restore the file name of the attached file
Let's express the result of analyzing Java bytecode with a class diagram
How to find out the Java version of a compiled class file
Sample program that returns the hash value of a file in Java
Check the domain by checking the MX record of the email address with java
I want to get the field name of the [Java] field. (Old tale tone)
Generate source code from JAR file with JD-GUI of Java Decompiler project