I'm using Bulk API to upload attachments and getting an error:
InvalidBatch : Failed to parse CSV header.
Number of Records Processed: 0
While I'm getting following error at the Salesforce side:
<error xmlns="http://www.force.com/2009/06/asyncapi/dataload">
<exceptionCode>InvalidBatch</exceptionCode>
<exceptionMessage>Records not processed</exceptionMessage>
</error>
I'm using Java, and it seems it errors while creating the batches like:
private static void createBatch(FileOutputStream tmpOut, File tmpFile,
List<BatchInfo> batchInfos, BulkConnection connection, JobInfo jobInfo)
throws IOException, AsyncApiException {
tmpOut.flush();
tmpOut.close();
FileInputStream tmpInputStream = new FileInputStream(tmpFile);
try {
Map<String, InputStream> attachments = new HashMap<String, InputStream>();
attachments.put("MyFile1.txt", new FileInputStream("C:\\Users\\user\\Desktop\\upload\\2014-04-18_231314.png"));
BatchInfo batchInfo = connection.createBatchWithInputStreamAttachments(jobInfo, tmpInputStream, attachments);
System.out.println(batchInfo!=null ? "BatchInfo is not null " : " BatchInfo is Null "); // I'm getting "BatchInfo is not null"
batchInfos.add(batchInfo);
} finally {
tmpInputStream.close();
}
} // END private void createBatch()
While for creating the job, I'm making sure the following parameters are set:
operation : OperationEnum.insert
object : Attachment
contentType : ContentType.ZIP_CSV
The CSV file as an input is:
Name,ParentId,Body
2014-04-18_231314.png,0019000000tZhfe,C:\Users\user\Desktop\upload\2014-04-18_231314.png
The above input is working fine using Apex Dataloader.
Please let me know what I'm doing wrong or is there anything I'm missing. I'm calling the method named: uploadBinaryAttachmentUsingBulkAPI()
from this code: PasteBin Code.
EDIT: I'm using Bulk API version 27.0.