简体   繁体   English

将文件上传到Google云端硬盘

[英]Upload files to Google drive

I go to Google drive, using the key (P12) 我使用密钥(P12)转到Google云端硬盘

I can browse folders, get data about the files, get lists of files in the Google drive. 我可以浏览文件夹,获取有关文件的数据,获取Google驱动器中的文件列表。 But I can not upload the file to Google drive. 但是我无法将文件上传到Google驱动器。

On the TEAM all set right (is owner) 在TEAM上,所有设置都正确(是所有者)

Why not give me the possibility to save the file? 为什么不给我保存文件的可能性?

Sample code I successfully get a list of folders: 示例代码我成功获取了文件夹列表:

def is_file_in_folder(service, folder_id, file_id):
  try:
    service.children().get(folderId=folder_id, childId=file_id).execute()
  except errors.HttpError, error:
    if error.resp.status == 404:
      return False
    else:
      print 'An error occurred: %s' % error
      raise error
  return True

The example code I'm trying to save file: 我正在尝试保存文件的示例代码:

def insert_file(service, title, description, parent_id, mime_type, filename):
  media_body = MediaFileUpload(filename, mimetype=mime_type, resumable=True)
  body = {
    'title': title,
    'description': description,
    'mimeType': mime_type
  }
  if parent_id:
    body['parents'] = [{'id': parent_id}]

  try:
    file = service.files().insert(body=body, media_body=media_body).execute()

    return file
  except errors.HttpError, error:
    print 'An error occured: %s' % error
    return None

Shows the error - ERROR 显示错误-ERROR

I assume that the file is trying to load, but something prevents him, as well as (resumable = True), he tries again and again, until the time. 我假设文件正在尝试加载,但是由于某种原因(以及(resumable = True)),他阻止了他一次又一次的尝试,直到那个时候。

What do I need to be able to upload files? 我需要什么才能上传文件?

Tried using the code to create a folder in Google drive, but shows the error (The authenticated user does not have the required access to the file) 尝试使用该代码在Google云端硬盘中创建文件夹,但显示错误(通过身份验证的用户无权访问该文件)

So how to get these rights? 那么如何获得这些权利?

Found the problem. 找到了问题。 It appears in the interface "Google Drive" were displayed right on the folder is read-only on this no one is able to upload files to it. 它出现在“ Google云端硬盘”界面中,并且在该文件夹上显示为只读,因此该用户无法将文件上传到该文件夹​​。 Because of this, and give an error and are only permitted to read. 因此,并给出错误,仅允许读取。

By the way, can someone know how to get a direct link to the file. 顺便说一句,有人可以知道如何直接链接到文件。 This format?: http://google.com/my_file.mp3 此格式?: http : //google.com/my_file.mp3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM