on 01-11-2022 6:37 PM
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;
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
74 | |
9 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.