Rather than directly upload file before check if file was already exists or not based on method return type, if file is not there then upload the file o.w show message like file alreay exists in the repository.
I have used the following code, i guess this might be useful to you.
public static boolean checkSpaceAvailable(String parSpacePath, String filename)
{
boolean result = true;
try
{
parSpacePath = StringEncription.encode(parSpacePath);
if(parSpacePath.contains("_x002f_")) parSpacePath = parSpacePath.replaceAll("_x002f_", "/");
if(parSpacePath.contains("/")) parSpacePath = parSpacePath.replaceAll("/", "/cm:");
//use "/" or "/cm:" before StringEncription.encode(filename) in the below line
parSpacePath = "/app:company_home"+parSpacePath+"/"+StringEncription.encode(filename);
System.out.println("Decoded Parent Space Path =======>>" + StringEncription.decode(parSpacePath));
Reference checkFolder = new Reference(storeRef, null, parSpacePath);
// Check to see if the parent folder has already been created or not
WebServiceFactory.getRepositoryService().get(new Predicate(new Reference[]{checkFolder}, storeRef, null));
}catch(Exception e){
System.out.println("!!! FILE ALREADY EXISTS IN THE REPOSITORY !!!");
result = false;
}
System.out.println("Space Available :" + result);
return result;
}
Regards,
Madhu