Asynchronous Document Upload
Monday, August 14, 2017 at 08:34amApologies if this is a duplicate. I may have trashed the last thread accidentally.
Hello everyone,
We've been seeing errors uploading documents asynchronously using jar with dependencies 11.0.2.
com.silanis.esl.sdk.EslException: Could not upload document to package.
at com.silanis.esl.sdk.service.PackageService.uploadApiDocument(PackageService.java:361)
at com.silanis.esl.sdk.service.PackageService.uploadDocument(PackageService.java:344)
at com.silanis.esl.sdk.EslClient.uploadDocument(EslClient.java:636)
at com.silanis.esl.sdk.EslClient.uploadDocument(EslClient.java:648)
Caused by: java.lang.IllegalArgumentException: id parameter cannot be null or empty
at com.silanis.esl.sdk.DocumentId.(DocumentId.java:20)
//Async
docsToCreate.parallelStream().forEach(doc -> uploadDocument(doc, createdPackage));
//Sync
docsToCreate.stream().forEach(doc -> uploadDocument(doc, createdPackage));
private static void uploadDocument(Document doc, DocumentPackage pack){
System.out.println(">>> Uploading: " + doc.getName());
Date starttime = new Date();
eslClient.uploadDocument(doc, pack.getId());
Date endPackageBuildTime = new Date();
System.out.println( " Uploading took: " + new Long(endPackageBuildTime.getTime() - starttime.getTime()) + "ms FOR: "
+ doc.getName());
}
Note: when using the Synchronous version, all documents upload successfully. I do not believe it is an issue with the package.
Reply to: Asynchronous Document Upload
Monday, August 14, 2017 at 11:25amReply to: Asynchronous Document Upload
Monday, August 14, 2017 at 09:42ameslClient.createPackageOneStep()call. This will create a multipart/form-data request and upload all your documents in one request.Reply to: Asynchronous Document Upload
Monday, August 14, 2017 at 11:05amReply to: Asynchronous Document Upload
Monday, August 14, 2017 at 11:42ampublic com.silanis.esl.sdk.Document uploadApiDocument( String packageId, String fileName, byte[] fileBytes, Document document ) { String path = template.urlFor(UrlTemplate.DOCUMENT_PATH) .replace("{packageId}", packageId) .build(); String documentJson = Serialization.toJson(document); try { String response = client.postMultipartFile(path, fileName, fileBytes, documentJson); //This will error because failure Json responses won’t be a document. com.silanis.esl.api.model.Document uploadedDocument = Serialization.fromJson(response, com.silanis.esl.api.model.Document.class);  return new DocumentConverter(uploadedDocument, getApiPackage(packageId)).toSDKDocument(); } catch (RequestException e) { throw new EslServerException("Could not upload document to package.", e); } catch (Exception e) { //Creating a new exception here hides the original cause that can be found in the String ‘response’. throw new EslException("Could not upload document to package.", e); } }However, this may be a topic for another thread. I've marked your answer as accepted.