本文整理汇总了Python中apiclient.http.MediaFileUpload.to_json方法的典型用法代码示例。如果您正苦于以下问题:Python MediaFileUpload.to_json方法的具体用法?Python MediaFileUpload.to_json怎么用?Python MediaFileUpload.to_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apiclient.http.MediaFileUpload
的用法示例。
在下文中一共展示了MediaFileUpload.to_json方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_http_request_to_from_json
# 需要导入模块: from apiclient.http import MediaFileUpload [as 别名]
# 或者: from apiclient.http.MediaFileUpload import to_json [as 别名]
def test_http_request_to_from_json(self):
def _postproc(*kwargs):
pass
http = httplib2.Http()
media_upload = MediaFileUpload(
datafile('small.png'), chunksize=500, resumable=True)
req = HttpRequest(
http,
_postproc,
'http://example.com',
method='POST',
body='{}',
headers={'content-type': 'multipart/related; boundary="---flubber"'},
methodId='foo',
resumable=media_upload)
json = req.to_json()
new_req = HttpRequest.from_json(json, http, _postproc)
self.assertEquals(new_req.headers,
{'content-type':
'multipart/related; boundary="---flubber"'})
self.assertEquals(new_req.uri, 'http://example.com')
self.assertEquals(new_req.body, '{}')
self.assertEquals(new_req.http, http)
self.assertEquals(new_req.resumable.to_json(), media_upload.to_json())
self.assertEquals(new_req.multipart_boundary, '---flubber--')
示例2: test_http_request_to_from_json
# 需要导入模块: from apiclient.http import MediaFileUpload [as 别名]
# 或者: from apiclient.http.MediaFileUpload import to_json [as 别名]
def test_http_request_to_from_json(self):
def _postproc(*kwargs):
pass
http = httplib2.Http()
media_upload = MediaFileUpload(datafile("small.png"), chunksize=500, resumable=True)
req = HttpRequest(
http,
_postproc,
"http://example.com",
method="POST",
body="{}",
headers={"content-type": 'multipart/related; boundary="---flubber"'},
methodId="foo",
resumable=media_upload,
)
json = req.to_json()
new_req = HttpRequest.from_json(json, http, _postproc)
self.assertEqual({"content-type": 'multipart/related; boundary="---flubber"'}, new_req.headers)
self.assertEqual("http://example.com", new_req.uri)
self.assertEqual("{}", new_req.body)
self.assertEqual(http, new_req.http)
self.assertEqual(media_upload.to_json(), new_req.resumable.to_json())
示例3: test_media_file_upload_to_from_json
# 需要导入模块: from apiclient.http import MediaFileUpload [as 别名]
# 或者: from apiclient.http.MediaFileUpload import to_json [as 别名]
def test_media_file_upload_to_from_json(self):
upload = MediaFileUpload(datafile("small.png"), chunksize=500, resumable=True)
self.assertEqual("image/png", upload.mimetype())
self.assertEqual(190, upload.size())
self.assertEqual(True, upload.resumable())
self.assertEqual(500, upload.chunksize())
self.assertEqual("PNG", upload.getbytes(1, 3))
json = upload.to_json()
new_upload = MediaUpload.new_from_json(json)
self.assertEqual("image/png", new_upload.mimetype())
self.assertEqual(190, new_upload.size())
self.assertEqual(True, new_upload.resumable())
self.assertEqual(500, new_upload.chunksize())
self.assertEqual("PNG", new_upload.getbytes(1, 3))
示例4: updateFile
# 需要导入模块: from apiclient.http import MediaFileUpload [as 别名]
# 或者: from apiclient.http.MediaFileUpload import to_json [as 别名]
def updateFile(service, fileID, path, createRevision):
log_msg("Updating file: " + path + ". Progress: ", newline="", color=Fore.CYAN)
file = service.files().get(fileId=fileID).execute()
media_body = MediaFileUpload(path, resumable=True)
if '"_mimetype": null' in media_body.to_json(): #unrecognized mimetype: set it manually
media_body = MediaFileUpload(path, mimetype=getMimeType(path), resumable=True)
request = service.files().update(fileId=fileID, body=file, newRevision=createRevision, media_body=media_body)
while True:
status, done = request.next_chunk()
if status:
progress = int(status.progress() * 100)
if progress < 100:
log_msg("%d%%" % progress, newline=" ... ")
if done:
log_msg("100%", newline=" ")
log_msg("Done!", color=Fore.CYAN)
return
示例5: uploadFile
# 需要导入模块: from apiclient.http import MediaFileUpload [as 别名]
# 或者: from apiclient.http.MediaFileUpload import to_json [as 别名]
def uploadFile(service, parentID, path):
log_msg("Uploading file: " + path + ". Progress: ", newline="", color=Fore.GREEN)
media_body = MediaFileUpload(path, resumable=True)
if '"_mimetype": null' in media_body.to_json(): #unrecognized mimetype: set it manually
media_body = MediaFileUpload(path, mimetype=getMimeType(path), resumable=True)
body = {"title": os.path.basename(path)}
if parentID: #set the parent folder
body["parents"] = [{"id": parentID}]
request = service.files().insert(media_body=media_body, body=body)
while True:
status, done = request.next_chunk()
if status:
progress = int(status.progress() * 100)
if progress < 100:
log_msg("%d%%" % progress, newline=" ... ")
if done:
id = request.execute()["id"]
log_msg("100%", newline=" ")
log_msg("Done! ID: " + id, color=Fore.GREEN)
return id