Advertisement
Guest User

Solution_BinaryAttachments

a guest
May 13th, 2014
1,005
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. public static void callingMethod(){        
  2. // Upload using BulkAPI
  3.             // Call the createJob()
  4.             // You send data in batches in separate HTTP POST requests.
  5.             JobInfo job = createJob(bConnection);
  6.             // Create a Batch with Binary Attachments
  7.             if (job != null) {
  8.                 System.out.println("Job is created.");
  9.                 List<BatchInfo> batchInfoList = new ArrayList<BatchInfo>();
  10.                 try {
  11.                     List<BatchInfo> batchInfos = new ArrayList<BatchInfo>();
  12.                     // Make the upload using BulkAPI
  13.                     createBatch(menifestFile, batchInfos, bConnection, job, attachments);
  14.                     batchInfoList.addAll(batchInfos);
  15.                 } catch (AsyncApiException ex){}
  16.                 if (batchInfoList.size() > 0) {
  17.                     closeJob(bConnection, job.getId());
  18.                     awaitCompletion(bConnection, job, batchInfoList);
  19.                     checkResults(bConnection, job, batchInfoList, emailInformation, acceptedList);
  20.                 }
  21.             } // END if (job != null)
  22. }
  23.  
  24.     // Main Method used for Binary Attachments using Bulk API
  25.     /**
  26.      * @param menifestFile
  27.      *                      The information held in XML / CSV format about the Name, Body and ParentId of the different files used. It requires us to place the information using relative path of Files.
  28.      * @param batchInfos
  29.      *                  The BatchInfo class used for storing the errors, recordId
  30.      * @param connection
  31.      *                  The BulkConnection used for createing batches. Here, a special method named createBatchWithInputStreamAttachments(JobInfo job, InputStream menifestFile, Map<String, InputStream> attachments) is used
  32.      * @param jobInfo
  33.      *                  The JobInfo reference used already used for creation of Job and to be used in referencing a Batch with the created Job's id
  34.      * @param attachments
  35.      *                  Map<String, InputStream> -> Key - The FileName must be matched with the Name of Menifest File
  36.      *                                              Value - The actual path-> absolute path of the File
  37.      * @throws IOException
  38.      * @throws AsyncApiException
  39.      */
  40.     private static void createBatch(FileInputStream menifestFile,
  41.             List<BatchInfo> batchInfos, BulkConnection connection, JobInfo jobInfo, Map<String, InputStream> attachments)
  42.                     throws IOException, AsyncApiException{
  43.         // Dummy Data {{{{{//       Map<String, InputStream> att = new HashMap<String, InputStream>();
  44.         // att.put("2014-04-18_231314.png", new FileInputStream("C:\\Users\\user\\Desktop\\upload\\2014-04-18_231314.png"));
  45.         // att.put("request_copy.txt", new FileInputStream("C:\\Users\\user\\Desktop\\upload\\request_copy.txt"));}}}}}
  46.  
  47.         BatchInfo batchInfo = connection.createBatchWithInputStreamAttachments(jobInfo,
  48.                 //new FileInputStream("C:\\Users\\user\\Desktop\\upload\\request.txt"),
  49.                 menifestFile,
  50.                 //att
  51.                 attachments);
  52.         batchInfos.add(batchInfo);
  53.     } // END private static void createBatch(File tmpFiel, List<BatchInfo> batchInfos, BulkConnection connection, JobInfo jobInfo)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement