7

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.

  • How many attachments are you trying to upload? What size are they? – Alex Tennant May 10 '14 at 8:11
  • Currently I'm trying to upload only one attachment. But I would like to attach multiple attachments. – sanchit May 10 '14 at 18:19
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.