How to Upload Attachments via the BULK Api?
See original GitHub issueWhile 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:
- Created 8 years ago
- Comments:10 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
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
andstreamifier
).I’d like some thoughts from the jsforce team before making my pull request.