question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to Upload Attachments via the BULK Api?

See original GitHub issue

While I can upload attachments just fine via CRUD, I have to upload about 1000 files - which would be insane to do via REST api.

I’m trying to do it with the BULK api, but I get this dread error: “Binary field Body is only supported for content types ZIP_XML and ZIP_CSV”.

Setup

var bulkInsert = function(sObject, records) {
    return new Promise(function(resolve, reject) {
        console.log('>>> Starting batch insert of', records.length, sObject, 'records ...');
        sfConn.bulk.load(sObject, 'insert', records, function(err, results) {
            if (err) {
                reject(err);
            } else {
                resolve(results);
            }
        });
    });
};

Method #1:

bulkInsert('Attachment', [{
    ParentId: 'someSFId',
    Name: 'myImage',
    ContentType: 'image/jpeg',
    Body: Buffer(fs.readFileSync('/path/to/my/files'), 'binary').toString('base64')
}];

Method #2:

bulkInsert('Attachment', [{
    ParentId: 'someSFId',
    Name: 'myImage',
    ContentType: 'image/jpeg',
    Body: '/path/to/my/jpg'
}];

They both fail with Binary field Body is only supported for content types ZIP_XML and ZIP_CSV.

However, the REST api works just fine …

sfConn.sobject('Attachment').create({
    ParentId: 'someSFId',
    Name: 'myImage',
    ContentType: 'image/jpeg',
    Body: Buffer(fs.readFileSync('/path/to/my/files'), 'binary').toString('base64')
});

How can I get the BULK api to work as well?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
stomitacommented, May 10, 2016

@kylefarris If you already have a fork implementation please give us the PR and we would like to check if it is suitable for merge to master.

1reaction
kylefarriscommented, Apr 25, 2016

I’m working on this feature in my fork (read: I actually have it working). It’s really not that complicated to implement. I was just wondering how much of the functionality (zipping, etc…) should be incorporated into jsforce itself vs just showing how to do it in the documentation. The changes to jsforce itself were relatively minor (just allowing a user to choose the contentType), but if we wanted to have the full zipping capability built into the library, that would be a lot more extensive and would require a couple new dependencies (adm-zip and streamifier).

I’d like some thoughts from the jsforce team before making my pull request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Upload Attachments | Data Loader Guide
If you intend to upload with Bulk API, verify that Upload Bulk API Batch as Zip File on the Settings | Settings page...
Read more >
REST api to upload multiple notes and attachments at once
Yes, there are a few ways to upload files. You can use the API you referenced in your question (the "create new records"...
Read more >
Salesforce Bulk API 2.0 to Import Files with Command Line ...
Using Salesforce Bulk API 2.0 and CURL command line interface we can import large number of files to Salesforce instance as a job...
Read more >
Bulk API 2.0 and Bulk API Developer Guide
Bulk ingest jobs allow you to upload records to your org by using a CSV file representation. Bulk query jobs return records based...
Read more >
Bulk import attachments to Jira server issues via REST API
If you go directly to the 'Procedure' section, the attachments will be imported with the file ID as their name. Also, they will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found