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">
    <exceptionMessage>Records not processed</exceptionMessage>

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 {
    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"
    } finally {
} // 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:


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.

  • How many attachments are you trying to upload? What size are they? Commented May 10, 2014 at 8:11
  • Currently I'm trying to upload only one attachment. But I would like to attach multiple attachments.
    – sanchit
    Commented May 10, 2014 at 18:19

1 Answer 1


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 named request.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.

  1. I provided the Zip file path as tmpInpuStream and got the same error by calling:

    connection.createBatchWithInputStreamAttachments(jobInfo, tmpInputStream, attachments);

    (Same Error)

  2. Provided the path of menifest file as request.txt by calling:

    connection.createBatchWithInputStreamAttachments(jobInfo, tmpInputStream, attachments);

    (Same Error)

  3. 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 in Menifest file matching the Key of attachments Map.

    Also, the value of attachments Map containing the absolute path of File and Body of menifest file containing the relative path using #.
    Please find the code snippet attached here Binary File Attachments using Bulk API.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .