将文件上传到 AWS 存储桶 S3 中。

huangapple go评论81阅读模式
英文:

Upload file into aws bucket s3

问题

使用根用户,我创建了一个管理员用户。我使用管理员用户登录了AWS控制台。然而,当我尝试将文件上传到存储桶时,我收到了以下错误:

> 在 'FileReaderSync' 上执行 'readAsArrayBuffer' 失败:请求的文件无法读取,通常是由于在获取文件引用之后发生的权限问题。

将文件上传到 AWS 存储桶 S3 中。

英文:

With the root user, I created an admin user. I logged in to AWS console using the admin user. However, when I tried to upload a file into a bucket, I have received the error below:

> Failed to execute 'readAsArrayBuffer' on 'FileReaderSync': The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.

将文件上传到 AWS 存储桶 S3 中。

答案1

得分: 0

这不是AWS特定的问题,而是您的本地浏览器试图保护您。

请阅读 https://developer.mozilla.org/en-US/docs/Web/API/FileReaderSync/readAsArrayBuffer 上的错误列表,查看您的文件是否违反以下情况之一:

  • SecurityError DOMException

    • 如果检测到以下问题之一,则会引发此异常:
      • 资源已被第三方修改;
      • 同时执行了太多读取操作;
      • 资源指向的文件对于Web使用是不安全的(例如,它是系统文件)。
  • NotReadableError DOMException

    • 如果由于权限问题(例如并发锁定)而无法读取资源,则引发此异常。
  • EncodingError DOMException

    • 如果资源是数据URL并且超出了每个浏览器定义的限制长度,则引发此异常。

然后确保文件对浏览器是安全的可读的(例如,检查扩展名/媒体类型是否与文件内容匹配,检查是否存在恶意代码,检查文件是否在其他窗口中打开并被锁定以防止读取)。

如果这些尝试失败,而您必须以该格式上传文件,请使用AWS Cli (https://aws.amazon.com/cli/) 进行上传。

英文:

This is not an AWS specific issues, but your local browser attempting to protect you.

Read the error list at https://developer.mozilla.org/en-US/docs/Web/API/FileReaderSync/readAsArrayBuffer to see if your file falls foul of one of the following:

SecurityError DOMException
 - Thrown if one of the following problematic situation is detected:
    - the resource has been modified by a third party;
    - too many read are performed simultaneously;
    - the file pointed by the resource is unsafe for a use from the Web (like it is a system file).

NotReadableError DOMException
 - Thrown if the resource cannot be read due to a permission problem, like a concurrent lock.

EncodingError DOMException
 - Thrown if the resource is a data URL and exceed the limit length defined by each browser.

Then make the file safe for the browser to read. (e.g. check the extension/mime type matches the file contents, check no malicious code, check the file is not open in another window and locked from being read)

If that fails, and you must have that file up in that format, use AWS Cli (https://aws.amazon.com/cli/) to do the upload.

huangapple
  • 本文由 发表于 2023年7月7日 06:37:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632914.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定