def send_sample(self, filedata):
"""
Ugly wrapper for uploading a file in multipart/form-data
"""
endpoint = "/api/1.0/samples/"
headers = {"Accept-encoding": "gzip, deflate",
"X-API-Key": self.api_key}
method = "POST"
boundary = "70f6e331562f4b8f98e5f9590e0ffb8e"
headers["Content-type"] = "multipart/form-data; boundary=" + boundary
body = "--" + boundary
body += "\r\n"
body += "Content-Disposition: form-data; name=\"filename\"\r\n"
body += "\r\n"
body += idc.GetInputFile()
body += "\r\n\r\n"
body += "--" + boundary + "\r\n"
body += "Content-Disposition: form-data;"
body += "name=\"file\"; filename=\"file\"\r\n"
body += "\r\n"
body += filedata.read()
body += "\r\n--"
body += boundary
body += "--\r\n"
self.h_conn.request(method, endpoint, body, headers)
res = self.h_conn.getresponse()
data = res.read()
try:
result = json.loads(data)
except BaseException:
g_logger.exception("Cannot load json data from server")
result = None
return result
评论列表
文章目录