通过 AppScript 从 Google Drive 上传到 BOX 修改点:修改后的脚本:注意:参考:

问题描述

目前正在处理谷歌表并实现一个脚本,将文件从 Drive 上传Box 。 我进行了身份验证(我可以通过连接到 API 的脚本获取文件夹列表)但是当我到达上传部分时,我收到一个空请求并且文件没有上传到目标文件夹>

我的脚本如下:

df <- data.frame(side,R_var1,L_var1,R_var2,L_var2,R_var3,L_var3)

谢谢

解决方法

修改点:

  • 查看BOX API的“上传文件”官方文档时,发现如下curl示例。 Ref

    ssh into your instance 
    df -h -> will tell you the volume size
    lsblk -> display information about the block devices attached to your instance
    sudo growpart /dev/xvda 1
    df -h -> to verify the size again
    sudo resize2fs /dev/xvda1
    
  • 当运行 $ curl -i -X POST "https://upload.box.com/api/2.0/files/content" \ -H "Authorization: Bearer <ACCESS_TOKEN>" \ -H "Content-Type: multipart/form-data" \ -F attributes="{"name":"Contract.pdf","parent":{"id":"11446498"}}" \ -F file=@<FILE_NAME> 的请求时,似乎在 Google Apps Script 中,内容类型是自动创建的,包括边界。

当上面的 curl 命令转换为 Google Apps Script 后,会变成下面这样。

修改后的脚本:

multipart/form-data

注意:

  • 在此示例脚本中,假设您的访问令牌 function uploadFile() { var blob = DriveApp.getFileById('<I got my file ID here>').getBlob(); var service = getService(); var attributes = {"name":"test document.pdf","parent":{"id":"<I got my folder ID here>"}}; var requestBody = {attributes: Utilities.newBlob(JSON.stringify(attributes),"application/json"),file: blob}; var options = { method: "post",payload: requestBody,muteHttpExceptions: true,headers: {'Authorization': 'Bearer ' + service.getAccessToken()} }; var request = UrlFetchApp.fetch("https://upload.box.com/api/2.0/files/content",options); Logger.log(request.getContentText()); } 可用于使用 API 上传文件。请注意这一点。

参考: