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.
Best Answer
It seems that the Bulk API version 30 documentation gives the curl implementation by wrapping up all the contents in
Zip
containing a manifest file namedrequest.txt
. I got the solution using version 27.I tried using multiple inputs in which 3rd one worked as desired. Now, I'm able to upload multiple attachments.
I provided the
Zip file path
astmpInpuStream
and got the same error by calling:connection.createBatchWithInputStreamAttachments(jobInfo, tmpInputStream, attachments);
(Same Error)
Provided the path of menifest file as
request.txt
by calling:connection.createBatchWithInputStreamAttachments(jobInfo, tmpInputStream, attachments);
(Same Error)
After analyzing the Apex Data Loader functionality, I provided the path of menifest file as request.csv and calling:
(It worked)
connection.createBatchWithInputStreamAttachments(jobInfo, tmpInputStream, attachments);
bypassing createCSVFromBatches() method and the
Name
inMenifest
file matching theKey
ofattachments
Map.Also, the
value
ofattachments
Map
containing theabsolute
path of File andBody
ofmenifest
file containing therelative
path using#
.Please find the code snippet attached here Binary File Attachments using Bulk API.