微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决通过 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 上传文件。请注意这一点。

参考:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。