Calls to Adobe Services API never return. | Community
Skip to main content
May 7, 2024
Question

Calls to Adobe Services API never return.

  • May 7, 2024
  • 1 reply
  • 690 views

Using the following code, the call to createPdfOperation.Execute(executionContext); never returns.

 

 

private async Task ConvertToPDF() { try { if (checkedNodes.Count() == 0) return; localService.isLoading = true; // Initial setup, create credentials instance. Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder() .WithClientId(clientId) .WithClientSecret(clientSecret) .Build(); //Create an ExecutionContext using credentials and create a new operation instance. ExecutionContext executionContext = ExecutionContext.Create(credentials); foreach (FileNode bn in checkedNodes) { if (bn.ContentType == "SharePointFolder" || bn.ContentType == "Root" || bn.ContentType == "BlobPrefix") continue; IFile spDoc = await localService.DownloadSharePointDocument($"{SharePointPath}/{bn.Path}"); if (spDoc == null) continue; string mediaType = "UNSUPPORTED"; string fileExt = Path.GetExtension(bn.FileName).ToLower(); switch (fileExt) { case ".docx": mediaType = CreatePDFOperation.SupportedSourceFormat.DOCX.GetMediaType(); break; case ".doc": mediaType = CreatePDFOperation.SupportedSourceFormat.DOC.GetMediaType(); break; case ".xlsx": mediaType = CreatePDFOperation.SupportedSourceFormat.XLSX.GetMediaType(); break; case ".xls": mediaType = CreatePDFOperation.SupportedSourceFormat.XLS.GetMediaType(); break; default: mediaType = "UNSUPPORTED"; break; } if (mediaType == "UNSUPPORTED") { notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Error", Detail = $"{fileExt} files not supported.", Duration = -1 }); localService.isLoading = false; return; } Stream ms = await spDoc.GetContentAsync(); ms.Seek(0, 0); FileRef source = FileRef.CreateFromStream(ms, mediaType); CreatePDFOperation createPdfOperation = CreatePDFOperation.CreateNew(); createPdfOperation.SetInput(source); // Execute the operation. FileRef result = createPdfOperation.Execute(executionContext); // Save the result to the specified location. Stream outStream = new MemoryStream(); result.SaveAs(outStream); outStream.Seek(0, 0); string newFileName = Path.GetFileNameWithoutExtension(bn.FileName) + ".pdf"; string upResult = await localService.UploadSharePointDocument(currentSharePointFolder, newFileName, outStream, false); if (upResult != "SUCCESS") { notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Error", Detail = upResult, Duration = -1 }); localService.isLoading = false; return; } } string parentKeyValue = ParentObject.GetType().GetProperty(ParentKeyProperty).GetValue(ParentObject, null).ToString(); await Load(parentKeyValue); } catch (ServiceUsageException ex) { notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Service Usage", Detail = ex.Message, Duration = -1 }); } catch (ServiceApiException ex) { notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Service Api", Detail = ex.Message, Duration = -1 }); } catch (SDKException ex) { notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "SDK", Detail = ex.Message, Duration = -1 }); } catch (IOException ex) { notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "IO", Detail = ex.Message, Duration = -1 }); } catch (Exception ex) { notificationService.Notify(new NotificationMessage { Severity = NotificationSeverity.Error, Summary = "Error", Detail = ex.Message, Duration = -1 }); } finally { localService.isLoading = false; checkedNodes = new List<object>(); } }
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
May 8, 2024

Hi, 

Kindly check if the conditions are met to reach that code. Under the following conditions, the method won't be triggered.

 

Unsupported File Types: If the file extension doesn't match any of the supported types (".docx", ".doc", ".xlsx", ".xls"), the method returns early before reaching the .Execute method.

Exceptions: If any exceptions occur during the processing, the execution will jump to the respective catch block, and the .Execute method won't be reached.

Early Returns: There are other return statements within the loop that would cause the method to exit before reaching .Execute.

 

Hope this helps

Esteban Bustamante
DuanePfAuthor
May 13, 2024

I have verified that the execute line of code is being reached.  It just never returns.