cancel
Showing results for 
Search instead for 
Did you mean: 

Upload PDF file AzureBlob from CPI

former_member351576
Participant
0 Kudos

Hi All ,

SFTP to Azure Blob upload pdf file via CPI . i am able to see file at Azureblob, while opening pdf showing empty .

I have taken reference blog post https://blogs.sap.com/2021/03/17/connect-to-azureblob-from-cpi-using-azure-storage-jar/

using below groovy to upload the file .

<code>/*
Script to upload files to Azure Blob folder using parameters provided
 */
import com.sap.gateway.ip.core.customdev.util.Message
import java.util.HashMap
import com.microsoft.azure.storage.*
import com.microsoft.azure.storage.blob.*
import java.text.SimpleDateFormat

def Message processData(Message message) {
    def body = message.getBody(java.lang.String) as String
    map = message.getProperties()
    
    String accountName=map.get("AzureAccountName")
    String accountKey = map.get("AzureAccountKey")
    String containerRef =map.get("ContainerRef")
	String fileNameScheme = map.get("Filename")
	String timestamp = map.get("AddTimestamp")
    String storageConnectionString = "DefaultEndpointsProtocol=https;" + "AccountName=" + accountName+ ";" + "AccountKey=" + accountKey

    CloudStorageAccount account = CloudStorageAccount.parse(storageConnectionString)
    CloudBlobClient serviceClient = account.createCloudBlobClient()

    CloudBlobContainer container = serviceClient.getContainerReference(containerRef)
if(timestamp.equals("Y")){
    String pattern = "yyyyMMddHHmmss";
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
    String date = simpleDateFormat.format(new Date());
    fileNameScheme = fileNameScheme + "_" + date;
}
    String fileName = fileNameScheme+ ".pdf"
    String fileContent = body
    byte[] fileBytes = fileContent.getBytes()

    CloudBlockBlob blob = container.getBlockBlobReference(fileName)
    blob.uploadFromByteArray(fileBytes, 0, fileBytes.length)

    blob.getProperties().setContentType("application/pdf")
    blob.uploadProperties()
    message.setBody("File is created with name : "+fileName)

    return message;
}
daviddasilva
Active Contributor
0 Kudos

What is the question here?

julian_baldner2
Explorer
0 Kudos

I think the question is how we can fix the code that the file is uploaded to the blob and can be opened properly.

The current file is empty / destroyed. I have the same issue.

PDF is opening, but images within PDF war missing

Accepted Solutions (0)

Answers (1)

Answers (1)

julian_baldner2
Explorer
0 Kudos

I think the question is how we can fix the code that the file is uploaded to the blob and can be opened properly.

The current file is empty / destroyed. I have the same issue.

PDF is opening, but images within PDF war missing