0

I would like to add batch with csv file to a job in salesforce.com, according to docs. I use the following code to do that, but it does not work (no new objects appear in salesforce):

    headers = {
        'Content-Type': 'text/csv; charset=UTF-8',
        'X-SFDC-Session': client.sessionId
    }
    (_, host, path, _, _, _) = urlparse("https://%s/services/async/24.0/job/%s/batch" % (instance, job_id))
    csv_file = open('test.csv', "rb")
    t = csv_file.read()
    conn = httplib.HTTPSConnection(host)
    conn.request("POST", path, t, headers)
    response = conn.getresponse()
    rawResponse = response.read()

How can I attach file to request and send it?

szaman
  • 6,666
  • 13
  • 53
  • 81
  • You want to attach a file to the **request** as in attach a file to **conn.request** ? Or do you want to attach a file to the **django response** ? I'm wondering if this is a question about httplib or django... the tags state "django" rather than "httplib" – jpic May 17 '12 at 09:25
  • @jpic: I want to send file to salesforce.com so I want to attach it to request not response. You are right about tags. – szaman May 17 '12 at 09:34

2 Answers2

1

The thing with the HTTP protocol, is that it requires some boilerplate to generate an HTTP request with attached binary contents.

Either use the poster lib, either reuse a lower level code snippet as there are plenty.

jpic
  • 32,891
  • 5
  • 112
  • 113
1

the records aren't processed until you update the job status to indicate you've uploaded all the batches in the job. see the quickstart in the docs

superfell
  • 18,780
  • 4
  • 59
  • 81