Reputation: 342
I'm trying to upload a file to google drive from google app engine. I have tried 2 different ways but I lose information in both.
The first one is the next one:
-The html form:
<html><body><form id='myForm' method='post' action='/guardar'
enctype='multipart/form-data' >
<input type="file" id="doc" name="doc" >
<input type="submit" value="Enviar"></form>
</body></html>
-The python code:
class guardar(webapp.RequestHandler):
@decorator.oauth_required
def post(self):
http = decorator.http()
service = build('drive', 'v2', http=http)
thefile = self.request.get('doc')
media_body = MediaInMemoryUpload(thefile, mimetype='text/plain', resumable=True)
response = service.files().insert(body={'title': 'prueba_si','mimeType': 'text/plain'},media_body=media_body).execute()
This way I lose the mimetype of the uploaded file and the title too; and I need both.
I have tried this other way but it always says that such file does not exist:
-The html file:
<html><body><form id='myForm' method='post' action='/guardar' >
<input type="file" id="doc" name="doc" >
<input type="submit" value="Enviar"></form>
</body></html>
-The python code:
class guardar(webapp.RequestHandler):
@decorator.oauth_required
def post(self):
http = decorator.http()
service = build('drive', 'v2', http=http)
thefile = self.request.get('doc')
mime_type=mimetypes.guess_type(thefile,strict=True)
media_body = MediaFileUpload(filename, mimetype=mime_type, resumable=True)
response = service.files().insert(body={'title': 'prueba_si','mimeType': mime_type},media_body=media_body).execute()
Thanks a lot for the help!
Upvotes: 2
Views: 934
Reputation: 41633
You don't need to pass the mime type in the media upload and also in the metadata. I would leave it just in the media upload.
You should not lose the title information, but I cannot reproduce your error.
Upvotes: 1