Java – Dropbox V2 uploadbuilder: “string ‘path’ does not match pattern”
I'm trying to use Drop@R_817_2419 @The V2 API uploads my application data files (SQLite and preferences) from my Android application to my Drop@R_817_2419 @Account I can successfully start the client:
// Drop@R_817_2419@ authentication config = new DbxRequestConfig("drop@R_817_2419@/liikennevalot"); client = new DbxClientV2(config,ACCESS_TOKEN);
My app says the link has started, listing my user credentials:
FullAccount account = client.users().getCurrentAccount();
I can list my applications Drop@R_817_2419 @Files in directory:
ListFolderResult result = client.files().listFolder(""); while (true) { for (Metadata Metadata : result.getEntries()) { Log.d("DROP@R_817_2419@",Metadata.getPathLower()); } if (!result.getHasMore()) { break; } result = client.files().listFolderContinue(result.getCursor()); }
But when trying to upload from Android to Drop@R_817_2419 @App root
try (InputStream in = new FileInputStream(getExternalFilesDir(null) + "/" + "testi.txt")) { FileMetadata Metadata = client.files().uploadBuilder("") .withMode(WriteMode.OVERWRITE) .uploadAndFinish(in); }
I got an exception
java.lang.IllegalArgumentException: String 'path' does not match pattern
It points to client files(). Code line for uploadbuilder ('')
Checking the exception stack, I found that Drop@R_817_2419 @In API V2, the class commitinfo has a constructor, which gives me this exception
} else if(!Pattern.matches("(/(.|[\\r\\n])*)|(ns:[0-9]+(/.*)?)",path)) { throw new IllegalArgumentException("String \'path\' does not match pattern");
I don't know the meaning of Java regex from regex, so I really don't know what caused my exception Drop@R_817_2419 @The API V2 document says "" indicates that the application is Drop@R_817_2419 @The root folder in, so my client files(). Uploadbuilder ("")... Should be perfect valid code
I've also tried in my application Drop@R_817_2419 @Create a subdirectory "test" under the directory and change the code to client files(). Uploadbuilder ("test")... But get the same exception every time
Anyone can help me explain the regex, so can you give me a clue about what's wrong with my code?
Solution
The parameter you passed to uploadbuilder should be Drop@R_817_2419 @The path of the file to be uploaded in You passed in '' itself, which is not the allowed location for file upload because it does not contain a file name
Instead, you should pass in a value like "/ test. TXT", which tells you Drop@R_817_2419 @Upload the content as a file named "test. TXT" in root
Or, for example, if you specify "/ documents / test. TXT", it will be uploaded as a file named "test. TXT" to a folder named "documents"