1<?xml version="1.0" encoding="ascii"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 3 "DTD/xhtml1-transitional.dtd"> 4<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 5<head> 6 <title>googleapiclient.http.MediaFileUpload</title> 7 <link rel="stylesheet" href="epydoc.css" type="text/css" /> 8 <script type="text/javascript" src="epydoc.js"></script> 9</head> 10 11<body bgcolor="white" text="black" link="blue" vlink="#204080" 12 alink="#204080"> 13<!-- ==================== NAVIGATION BAR ==================== --> 14<table class="navbar" border="0" width="100%" cellpadding="0" 15 bgcolor="#a0c0ff" cellspacing="0"> 16 <tr valign="middle"> 17 <!-- Home link --> 18 <th> <a 19 href="googleapiclient-module.html">Home</a> </th> 20 21 <!-- Tree link --> 22 <th> <a 23 href="module-tree.html">Trees</a> </th> 24 25 <!-- Index link --> 26 <th> <a 27 href="identifier-index.html">Indices</a> </th> 28 29 <!-- Help link --> 30 <th> <a 31 href="help.html">Help</a> </th> 32 33 <th class="navbar" width="100%"></th> 34 </tr> 35</table> 36<table width="100%" cellpadding="0" cellspacing="0"> 37 <tr valign="top"> 38 <td width="100%"> 39 <span class="breadcrumbs"> 40 <a href="googleapiclient-module.html">Package googleapiclient</a> :: 41 <a href="googleapiclient.http-module.html">Module http</a> :: 42 Class MediaFileUpload 43 </span> 44 </td> 45 <td> 46 <table cellpadding="0" cellspacing="0"> 47 <!-- hide/show private --> 48 <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink" 49 onclick="toggle_private();">hide private</a>]</span></td></tr> 50 <tr><td align="right"><span class="options" 51 >[<a href="frames.html" target="_top">frames</a 52 >] | <a href="googleapiclient.http.MediaFileUpload-class.html" 53 target="_top">no frames</a>]</span></td></tr> 54 </table> 55 </td> 56 </tr> 57</table> 58<!-- ==================== CLASS DESCRIPTION ==================== --> 59<h1 class="epydoc">Class MediaFileUpload</h1><p class="nomargin-top"><span class="codelink"><a href="googleapiclient.http-pysrc.html#MediaFileUpload">source code</a></span></p> 60<center> 61 62</center> 63<hr /> 64<pre class="literalblock"> 65A MediaUpload for a file. 66 67Construct a MediaFileUpload and pass as the media_body parameter of the 68method. For example, if we had a service that allowed uploading images: 69 70 71 media = MediaFileUpload('cow.png', mimetype='image/png', 72 chunksize=1024*1024, resumable=True) 73 farm.animals().insert( 74 id='cow', 75 name='cow.png', 76 media_body=media).execute() 77 78Depending on the platform you are working on, you may pass -1 as the 79chunksize, which indicates that the entire file should be uploaded in a single 80request. If the underlying platform supports streams, such as Python 2.6 or 81later, then this can be very efficient as it avoids multiple connections, and 82also avoids loading the entire file into memory before sending it. Note that 83Google App Engine has a 5MB limit on request size, so you should never set 84your chunksize larger than 5MB, or to -1. 85 86</pre> 87 88<!-- ==================== INSTANCE METHODS ==================== --> 89<a name="section-InstanceMethods"></a> 90<table class="summary" border="1" cellpadding="3" 91 cellspacing="0" width="100%" bgcolor="white"> 92<tr bgcolor="#70b0f0" class="table-header"> 93 <td colspan="2" class="table-header"> 94 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 95 <tr valign="top"> 96 <td align="left"><span class="table-header">Instance Methods</span></td> 97 <td align="right" valign="top" 98 ><span class="options">[<a href="#section-InstanceMethods" 99 class="privatelink" onclick="toggle_private();" 100 >hide private</a>]</span></td> 101 </tr> 102 </table> 103 </td> 104</tr> 105<tr> 106 <td width="15%" align="right" valign="top" class="summary"> 107 <span class="summary-type"> </span> 108 </td><td class="summary"> 109 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 110 <tr> 111 <td><span class="summary-sig"><a href="googleapiclient.http.MediaFileUpload-class.html#__init__" class="summary-sig-name">__init__</a>(<span class="summary-sig-arg">self</span>, 112 <span class="summary-sig-arg">filename</span>, 113 <span class="summary-sig-arg">mimetype</span>=<span class="summary-sig-default">None</span>, 114 <span class="summary-sig-arg">chunksize</span>=<span class="summary-sig-default">DEFAULT_CHUNK_SIZE</span>, 115 <span class="summary-sig-arg">resumable</span>=<span class="summary-sig-default">False</span>)</span><br /> 116 Constructor.</td> 117 <td align="right" valign="top"> 118 <span class="codelink"><a href="googleapiclient.http-pysrc.html#MediaFileUpload.__init__">source code</a></span> 119 120 </td> 121 </tr> 122 </table> 123 124 </td> 125 </tr> 126<tr> 127 <td width="15%" align="right" valign="top" class="summary"> 128 <span class="summary-type"> </span> 129 </td><td class="summary"> 130 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 131 <tr> 132 <td><span class="summary-sig"><a href="googleapiclient.http.MediaFileUpload-class.html#to_json" class="summary-sig-name">to_json</a>(<span class="summary-sig-arg">self</span>)</span><br /> 133 Creating a JSON representation of an instance of MediaFileUpload.</td> 134 <td align="right" valign="top"> 135 <span class="codelink"><a href="googleapiclient.http-pysrc.html#MediaFileUpload.to_json">source code</a></span> 136 137 </td> 138 </tr> 139 </table> 140 141 </td> 142 </tr> 143 <tr> 144 <td colspan="2" class="summary"> 145 <p class="indent-wrapped-lines"><b>Inherited from <code><a href="googleapiclient.http.MediaIoBaseUpload-class.html">MediaIoBaseUpload</a></code></b>: 146 <code><a href="googleapiclient.http.MediaIoBaseUpload-class.html#chunksize">chunksize</a></code>, 147 <code><a href="googleapiclient.http.MediaIoBaseUpload-class.html#getbytes">getbytes</a></code>, 148 <code><a href="googleapiclient.http.MediaIoBaseUpload-class.html#has_stream">has_stream</a></code>, 149 <code><a href="googleapiclient.http.MediaIoBaseUpload-class.html#mimetype">mimetype</a></code>, 150 <code><a href="googleapiclient.http.MediaIoBaseUpload-class.html#resumable">resumable</a></code>, 151 <code><a href="googleapiclient.http.MediaIoBaseUpload-class.html#size">size</a></code>, 152 <code><a href="googleapiclient.http.MediaIoBaseUpload-class.html#stream">stream</a></code> 153 </p> 154 <div class="private"> <p class="indent-wrapped-lines"><b>Inherited from <code><a href="googleapiclient.http.MediaUpload-class.html">MediaUpload</a></code></b> (private): 155 <code><a href="googleapiclient.http.MediaUpload-class.html#_to_json" onclick="show_private();">_to_json</a></code> 156 </p></div> 157 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>: 158 <code>__delattr__</code>, 159 <code>__format__</code>, 160 <code>__getattribute__</code>, 161 <code>__hash__</code>, 162 <code>__new__</code>, 163 <code>__reduce__</code>, 164 <code>__reduce_ex__</code>, 165 <code>__repr__</code>, 166 <code>__setattr__</code>, 167 <code>__sizeof__</code>, 168 <code>__str__</code>, 169 <code>__subclasshook__</code> 170 </p> 171 </td> 172 </tr> 173</table> 174<!-- ==================== CLASS METHODS ==================== --> 175<a name="section-ClassMethods"></a> 176<table class="summary" border="1" cellpadding="3" 177 cellspacing="0" width="100%" bgcolor="white"> 178<tr bgcolor="#70b0f0" class="table-header"> 179 <td colspan="2" class="table-header"> 180 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 181 <tr valign="top"> 182 <td align="left"><span class="table-header">Class Methods</span></td> 183 <td align="right" valign="top" 184 ><span class="options">[<a href="#section-ClassMethods" 185 class="privatelink" onclick="toggle_private();" 186 >hide private</a>]</span></td> 187 </tr> 188 </table> 189 </td> 190</tr> 191 <tr> 192 <td colspan="2" class="summary"> 193 <p class="indent-wrapped-lines"><b>Inherited from <code><a href="googleapiclient.http.MediaUpload-class.html">MediaUpload</a></code></b>: 194 <code><a href="googleapiclient.http.MediaUpload-class.html#new_from_json">new_from_json</a></code> 195 </p> 196 </td> 197 </tr> 198</table> 199<!-- ==================== STATIC METHODS ==================== --> 200<a name="section-StaticMethods"></a> 201<table class="summary" border="1" cellpadding="3" 202 cellspacing="0" width="100%" bgcolor="white"> 203<tr bgcolor="#70b0f0" class="table-header"> 204 <td colspan="2" class="table-header"> 205 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 206 <tr valign="top"> 207 <td align="left"><span class="table-header">Static Methods</span></td> 208 <td align="right" valign="top" 209 ><span class="options">[<a href="#section-StaticMethods" 210 class="privatelink" onclick="toggle_private();" 211 >hide private</a>]</span></td> 212 </tr> 213 </table> 214 </td> 215</tr> 216<tr> 217 <td width="15%" align="right" valign="top" class="summary"> 218 <span class="summary-type"> </span> 219 </td><td class="summary"> 220 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 221 <tr> 222 <td><span class="summary-sig"><a name="from_json"></a><span class="summary-sig-name">from_json</span>(<span class="summary-sig-arg">s</span>)</span></td> 223 <td align="right" valign="top"> 224 <span class="codelink"><a href="googleapiclient.http-pysrc.html#MediaFileUpload.from_json">source code</a></span> 225 226 </td> 227 </tr> 228 </table> 229 230 </td> 231 </tr> 232</table> 233<!-- ==================== PROPERTIES ==================== --> 234<a name="section-Properties"></a> 235<table class="summary" border="1" cellpadding="3" 236 cellspacing="0" width="100%" bgcolor="white"> 237<tr bgcolor="#70b0f0" class="table-header"> 238 <td colspan="2" class="table-header"> 239 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 240 <tr valign="top"> 241 <td align="left"><span class="table-header">Properties</span></td> 242 <td align="right" valign="top" 243 ><span class="options">[<a href="#section-Properties" 244 class="privatelink" onclick="toggle_private();" 245 >hide private</a>]</span></td> 246 </tr> 247 </table> 248 </td> 249</tr> 250 <tr> 251 <td colspan="2" class="summary"> 252 <p class="indent-wrapped-lines"><b>Inherited from <code>object</code></b>: 253 <code>__class__</code> 254 </p> 255 </td> 256 </tr> 257</table> 258<!-- ==================== METHOD DETAILS ==================== --> 259<a name="section-MethodDetails"></a> 260<table class="details" border="1" cellpadding="3" 261 cellspacing="0" width="100%" bgcolor="white"> 262<tr bgcolor="#70b0f0" class="table-header"> 263 <td colspan="2" class="table-header"> 264 <table border="0" cellpadding="0" cellspacing="0" width="100%"> 265 <tr valign="top"> 266 <td align="left"><span class="table-header">Method Details</span></td> 267 <td align="right" valign="top" 268 ><span class="options">[<a href="#section-MethodDetails" 269 class="privatelink" onclick="toggle_private();" 270 >hide private</a>]</span></td> 271 </tr> 272 </table> 273 </td> 274</tr> 275</table> 276<a name="__init__"></a> 277<div> 278<table class="details" border="1" cellpadding="3" 279 cellspacing="0" width="100%" bgcolor="white"> 280<tr><td> 281 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 282 <tr valign="top"><td> 283 <h3 class="epydoc"><span class="sig"><span class="sig-name">__init__</span>(<span class="sig-arg">self</span>, 284 <span class="sig-arg">filename</span>, 285 <span class="sig-arg">mimetype</span>=<span class="sig-default">None</span>, 286 <span class="sig-arg">chunksize</span>=<span class="sig-default">DEFAULT_CHUNK_SIZE</span>, 287 <span class="sig-arg">resumable</span>=<span class="sig-default">False</span>)</span> 288 <br /><em class="fname">(Constructor)</em> 289 </h3> 290 </td><td align="right" valign="top" 291 ><span class="codelink"><a href="googleapiclient.http-pysrc.html#MediaFileUpload.__init__">source code</a></span> 292 </td> 293 </tr></table> 294 295 <pre class="literalblock"> 296Constructor. 297 298Args: 299 filename: string, Name of the file. 300 mimetype: string, Mime-type of the file. If None then a mime-type will be 301 guessed from the file extension. 302 chunksize: int, File will be uploaded in chunks of this many bytes. Only 303 used if resumable=True. Pass in a value of -1 if the file is to be 304 uploaded in a single chunk. Note that Google App Engine has a 5MB limit 305 on request size, so you should never set your chunksize larger than 5MB, 306 or to -1. 307 resumable: bool, True if this is a resumable upload. False means upload 308 in a single request. 309 310</pre> 311 <dl class="fields"> 312 <dt>Decorators:</dt> 313 <dd><ul class="nomargin-top"> 314 <li><code>@util.positional(2)</code></li> 315 </ul></dd> 316 <dt>Overrides: 317 object.__init__ 318 </dt> 319 </dl> 320</td></tr></table> 321</div> 322<a name="to_json"></a> 323<div> 324<table class="details" border="1" cellpadding="3" 325 cellspacing="0" width="100%" bgcolor="white"> 326<tr><td> 327 <table width="100%" cellpadding="0" cellspacing="0" border="0"> 328 <tr valign="top"><td> 329 <h3 class="epydoc"><span class="sig"><span class="sig-name">to_json</span>(<span class="sig-arg">self</span>)</span> 330 </h3> 331 </td><td align="right" valign="top" 332 ><span class="codelink"><a href="googleapiclient.http-pysrc.html#MediaFileUpload.to_json">source code</a></span> 333 </td> 334 </tr></table> 335 336 <pre class="literalblock"> 337Creating a JSON representation of an instance of MediaFileUpload. 338 339Returns: 340 string, a JSON representation of this instance, suitable to pass to 341 from_json(). 342 343</pre> 344 <dl class="fields"> 345 <dt>Overrides: 346 <a href="googleapiclient.http.MediaUpload-class.html#to_json">MediaUpload.to_json</a> 347 </dt> 348 </dl> 349</td></tr></table> 350</div> 351<br /> 352<!-- ==================== NAVIGATION BAR ==================== --> 353<table class="navbar" border="0" width="100%" cellpadding="0" 354 bgcolor="#a0c0ff" cellspacing="0"> 355 <tr valign="middle"> 356 <!-- Home link --> 357 <th> <a 358 href="googleapiclient-module.html">Home</a> </th> 359 360 <!-- Tree link --> 361 <th> <a 362 href="module-tree.html">Trees</a> </th> 363 364 <!-- Index link --> 365 <th> <a 366 href="identifier-index.html">Indices</a> </th> 367 368 <!-- Help link --> 369 <th> <a 370 href="help.html">Help</a> </th> 371 372 <th class="navbar" width="100%"></th> 373 </tr> 374</table> 375<table border="0" cellpadding="0" cellspacing="0" width="100%%"> 376 <tr> 377 <td align="left" class="footer"> 378 Generated by Epydoc 3.0.1 on Mon Jun 5 13:38:40 2017 379 </td> 380 <td align="right" class="footer"> 381 <a target="mainFrame" href="http://epydoc.sourceforge.net" 382 >http://epydoc.sourceforge.net</a> 383 </td> 384 </tr> 385</table> 386 387<script type="text/javascript"> 388 <!-- 389 // Private objects are initially displayed (because if 390 // javascript is turned off then we want them to be 391 // visible); but by default, we want to hide them. So hide 392 // them unless we have a cookie that says to show them. 393 checkCookie(); 394 // --> 395</script> 396</body> 397</html> 398